首页 > 解决方案 > discord.py 通过频道上的消息踢特定用户

问题描述

我一直在为我和我的朋友制作不和谐机器人。我想让我们服务器上的每个人(无论他们的等级)都能踢特定的人。让他的名字叫乔治

那是乔治:

George = {
'id' : '123456789',
'username' : 'george12'
}

我试图以这种方式做到这一点:

if message.content.startswith("Goodbay George"):
   await george['id'].kick

和这个:

@bot.command()
@commands.has_permissions(kick_members = True)
@commands.bot_has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason = None):
  await member.kick(reason = reason)


@bot.event
async def on_message(message):

   if message.content.startswith("Goodbay George"):
      await kick(george['id'])      ### im not sure how provide member as argument, I got kick function from this forum

但是这些选项都不起作用。我怎样才能做到我所期望的?(开头说的)

标签: pythondiscord.py

解决方案


从 dict访问id密钥时george,您会得到一个字符串(George 的 ID),要真正踢某人,它必须是一个discord.Member实例,才能使用它Guild.get_member(这需要一个整数)

if message.content.startswith("Goodbay George"):
    george_id = int(george['id']) # already casting to an integer
    member = message.guild.get_member(george_id)
    await member.kick()

参考:


推荐阅读