Issue with voice channel name modification
I’m trying to build a Discord bot that can change a voice channel’s name using a specific command. The voice channel starts with the name “0” and I want it to go up by one number each time I run the command.
import discord
from discord.ext import commands
# Bot configuration
BOT_TOKEN = 'YOUR_BOT_TOKEN_HERE'
TARGET_CHANNEL_ID = 'YOUR_CHANNEL_ID_HERE'
# Counter variable
number = 0
# Bot setup with permissions
intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
intents.voice_states = True
bot = commands.Bot(command_prefix='$', intents=intents)
# Function to change channel name
async def modify_channel_title(voice_ch):
global number
number += 1
await voice_ch.edit(name=f"Room {number}")
# Command to trigger the update
@bot.command()
async def update(ctx):
target_channel = bot.get_channel(int(TARGET_CHANNEL_ID))
if target_channel:
await modify_channel_title(target_channel)
await ctx.send("Channel name has been updated successfully.")
else:
await ctx.send("Could not locate the specified channel.")
# Bot ready event
@bot.event
async def on_ready():
print(f'Bot is online as {bot.user}')
print(f'Bot ID: {bot.user.id}')
print('Ready to process commands')
# Start the bot
bot.run(BOT_TOKEN)
When I execute the $update command, nothing seems to happen at all. The bot doesn’t respond and the channel name stays the same. I’m not sure what’s wrong with my code or what steps I should take to fix this problem.