繁体   English   中英

在 Python 中编程 Discord 机器人 - 如何发出踢命令?

[英]Programming a Discord bot in Python- How do I make a kick command?

我想制作一个在提示时踢指定用户的命令。 这是我所拥有的:

@bot.command()
async def kick(ctx, user: discord.Member, *, reason="No reason provided"):
        await user.kick(reason=reason)
        kick = discord.Embed(title=f"Kicked {user.name}!", description=f"Reason: {reason}\nBy: {ctx.author.mention}")
        await ctx.message.delete()
        await ctx.channel.send(embed=kick)
        await user.send(embed=kick)

好像没用,有什么建议吗?

这里有两件事。 由于您的on_message事件正在使用client.event ,这意味着您应该将bot.command替换为client.command ,如下所示:

@client.command()
async def kick(ctx, user: discord.Member, *, reason="No reason provided"):
        await user.kick(reason=reason)
        kick = discord.Embed(title=f"Kicked {user.name}!", description=f"Reason: {reason}\nBy: {ctx.author.mention}")
        await ctx.message.delete()
        await ctx.channel.send(embed=kick)
        await user.send(embed=kick)

如果您的 kick 命令仍然不起作用,在on_message事件的最后,您应该添加await client.process_commands(message) 我将在下面举一个例子:

@client.event
async def on_message(message):
    if message.content == "Test":
        print("recieved")
    await client.process_commands(message)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM