python - 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
但是这些选项都不起作用。我怎样才能做到我所期望的?(开头说的)
解决方案
从 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()
参考:
推荐阅读
- javascript - Express JS:如何通过标头请求管理路由?
- css - 为没有父元素的子元素应用 CSS 选择器
- url - 我可以对 Jupyter Lab 中的项目进行永久链接吗?
- r - 从 1 中减去存储在列表列表中的矩阵中的每个值
- soap - setRequestproperty() 已连接错误(也在非调试模式下)
- amazon-s3 - EMR 上的 PySpark 作业适用于较小的文件,但不适用于较大的文件
- python - protobuf : 可选属性的值未清除
- delphi - 使用 ENTER 选择时 DBLookUpComboBox 不会将记录保存在数据库中 - Delphi 7
- arrays - 增加无类型数组参数的方法
- javascript - “没有可用的付款方式。” Braintree 沙箱出错