我试图用discord.py对投票系统进行编码,我希望bot发送用户发送的消息,在我发现之前,我可以通过编码async def voting(ctx, *text):
并将*符号放在文本参数前面来实现这一点,但当我试图对bot进行编码,以便他发送文本参数时,错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: send() takes from 1 to 2 positional arguments but 6 were given
显示在控制台中。我已经试过了,比如把它放在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)')
这个代码非常糟糕
此外,如果要将其作为字符串传递,请使用以下命令:
client.add_reaction
它不再是一个东西了,如果你用的是discord.py 1.0+
它是Message.add_reaction
client.wait_for(event)
,下面是一个示例^{}
相关问题 更多 >
编程相关推荐