【问题标题】:How do you create a kick command in discord python?如何在 discord python 中创建 kick 命令?
【发布时间】:2021-11-20 21:21:14
【问题描述】:

@client.command 不起作用,所以我尝试这样做

if message.content.startswith(f'-kick {member}'):
      member.ban()
      await message.channel.send(f'User {member} has been kicked')

请帮帮我

【问题讨论】:

标签: python discord.py


【解决方案1】:

使用 on_message 作为 kick 命令会更难,所以尝试使用 client.command 像这样:

@client.command() # command decorator
async def kick(ctx, member: discord.Member): # kick function
  await ctx.guild.kick(member) # kicks the member from the guild that the command was used in
  await ctx.send(f"User {member} has been kicked") # telling that the member has been kicked

如果需要,您可以通过添加另一个参数来添加原因

【讨论】:

  • 如何知道消息是否是命令?我尝试使用我的前缀,但它在服务器和控制台上没有显示任何内容
  • 你是什么意思@H1387XD?您必须使用 bot = commands.Bot(command_prefix="<your prefix here>") 行定义您的机器人
  • 我使用了那一行,但@bot.command() 如何知道它是命令还是普通消息
  • 更新:我发现我必须删除 on_message 才能正常工作,谢谢!
【解决方案2】:

您只需使用member.ban() 而不是member.kick(),这很简单

if message.content.startswith(f'-kick {member}'):
  member.kick()
  await message.channel.send(f'User {member} has been kicked')

【讨论】:

    猜你喜欢
    • 2021-03-01
    • 2018-03-04
    • 1970-01-01
    • 2021-01-05
    • 2020-08-07
    • 2021-08-12
    • 2019-07-31
    • 2021-07-18
    • 2019-08-22
    相关资源
    最近更新 更多