Я создал команду присоединения для своего бота discord.py. Пользователь может указать канал, куда бот будет подключаться, или не указывать его, и тогда бот будет подключаться к каналу к пользователю. Но это не работает. Ошибок нет. Всегда пишет "Ошибка! Канал не найден".
@bot.command()
async def join(ctx, *channelname):
if channelname is None:
try:
channel=ctx.author.voice.channel
await channel.connect()
await ctx.send("Joined!")
except AttributeError:
await ctx.send("Error! You are not connected to the channel available to me.")
except Exception as e:
print(e)
else:
channel = discord.utils.get(ctx.guild.channels, name=channelname, type = "ChannelType.voice")
try:
await channel.connect()
await ctx.send("Joined!")
except AttributeError:
await ctx.send("Error! Channel not found.")
except Exception as e:
print(e)
Вы должны определить свою команду таким образом, чтобы channelname = None
. В дополнение к этому тип канала является объектом, а не строкой.
@bot.command()
async def join(ctx, *, channelname=None):
if channelname is None:
try:
channel = ctx.author.voice.channel
await channel.connect()
await ctx.send("Joined!")
except AttributeError:
await ctx.send("Error! You are not connected to the channel available to me.")
except Exception as e:
print(e)
else:
channel = discord.utils.get(
ctx.guild.channels, name=channelname, type=discord.ChannelType.voice)
try:
await channel.connect()
await ctx.send("Joined!")
except AttributeError:
await ctx.send("Error! Channel not found.")
except Exception as e:
print(e)