Discord.py send()接受1到2个位置参数



我试图用discord.py对投票系统进行编码。我希望机器人程序发送用户在我发现之前发送的消息。我可以通过编码async def voting(ctx, *text):并将*符号放在文本参数前面来完成这一操作,但当我试图对机器人程序进行编码以使其发送文本参数时,错误:

discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:send((从1到2个位置参数中获取,但有6个被赋予

将显示在控制台中。我已经尝试过把它放在f字符串中,但它不起作用。

这是这个命令的完整代码

@client.command()
async def voting(ctx, *text):
await ctx.channel.purge(limit = 1)
message = await ctx.send(*text)
cross = client.get_emoji(790243377953636372)
check = client.get_emoji(790243459050110977)
voting_cross = 0
voting_check = 0
await client.add_reaction(message, emoji = cross)
await client.add_reaction( emoji = check )
@client.event
async def on_reaction_add(reaction, user):
reaction_channel = reaction.message.channel
voting_channel = client.get_channel(voting_channel_id)
if reaction_channel == voting_channel :
if str(reaction.emoji) == "✅":
voting_check = voting_check + 1
print(f'{user} has votet with ')
if str(reaction.emoji) == "❌":
voting_cross = voting_cross + 1
print(f'{user} has votet with ')
@client.command()
async def results(ctx):
if voting_check > voting_cross :
await ctx.send(f'More people votet for :greencheckmark: ({voting_check} votes)')
else :
await ctx.send(f'More people votet for :redcross: ({voting_cross} votes)')

这段代码真的很糟糕。

  1. 您正在打开列表,而不是加入列表
>>> lst = [1, 2, 3]
>>> print(lst)
[1, 2, 3]
>>> print(*lst)
1 2 3 # It's not the same, you need to join it using str.join(list)
>>> ' '.join(lst)
'1 2 3'

如果你想把它作为字符串传递,也可以使用这个:

@client.command()
async def voting(ctx, *, text):
  1. client.add_reaction不再是一回事,如果您使用的是discord.py 1.0+,它就是Message.add_reaction
await message.add_reaction(whatever)
  1. 您不将事件放入命令中,而是使用client.wait_for(event),下面是一个示例
@client.command()
async def voting(ctx, *text):
# add the reactions to the message here or whatever
# Here's how to wait for a reaction
def check_reaction(reaction, user):
return user == ctx.author
reaction, user = await client.wait_for('message', check=check_reaction)
# Here's how to wait for a message
def check_message(message):
return message.author == ctx.author
message = await client.wait_for('message', check=check_message)

wait_for

相关内容

最新更新