为什么我的 discord 机器人没有连接到重写 discord.py 的频道?
why isn't my discord bot connecting to the channel with discord.py rewritten?
好的,所以我对 python 和编程还是很陌生,一般来说试图让我的 discord 机器人加入我的频道,但是当我键入命令时它没有加入。我尝试了几种不同的方法。这是代码:
@client.event
async def voice_chat(message, VoiceChannel):
if message.content == "!join":
musicplayer = VoiceChannel.connect()
我也尝试用客户端替换两个 VoiceChannels,但它仍然不起作用,我也尝试用 await 替换 if message.content,但没有任何尝试奏效。有人知道这段代码有什么问题吗?
您需要使用commands.command()
@commands.command()
async def join(self, ctx, voice_channel):
voice_channel.connect()
我建议也使用 VoiceChannelConverter
。所以总的来说,你的函数应该看起来有点像这样减去你想要的任何其他逻辑。
from discord.ext import commands
@commands.command()
async def join(self, ctx, voice_channel: commands.VoiceChannelConverter):
try:
await voice_channel.connect()
except commands.BotMissingPermissions as error:
#send them a prettied up message saying HEY I NEED {} PERMS!
await ctx.send(f"I have joined: {voice_channel}")
还要注意这个应该在齿轮/extension内,所以要考虑到这一点。至少这是正常的约定,就像 "voice" 齿轮。
好的,所以我对 python 和编程还是很陌生,一般来说试图让我的 discord 机器人加入我的频道,但是当我键入命令时它没有加入。我尝试了几种不同的方法。这是代码:
@client.event
async def voice_chat(message, VoiceChannel):
if message.content == "!join":
musicplayer = VoiceChannel.connect()
我也尝试用客户端替换两个 VoiceChannels,但它仍然不起作用,我也尝试用 await 替换 if message.content,但没有任何尝试奏效。有人知道这段代码有什么问题吗?
您需要使用commands.command()
@commands.command()
async def join(self, ctx, voice_channel):
voice_channel.connect()
我建议也使用 VoiceChannelConverter
。所以总的来说,你的函数应该看起来有点像这样减去你想要的任何其他逻辑。
from discord.ext import commands
@commands.command()
async def join(self, ctx, voice_channel: commands.VoiceChannelConverter):
try:
await voice_channel.connect()
except commands.BotMissingPermissions as error:
#send them a prettied up message saying HEY I NEED {} PERMS!
await ctx.send(f"I have joined: {voice_channel}")
还要注意这个应该在齿轮/extension内,所以要考虑到这一点。至少这是正常的约定,就像 "voice" 齿轮。