繁体   English   中英

踢在 discord 机器人中未定义

[英]kick is undefined in discord bot

我制作了一个机器人,在 discord 上 ping @everyone 时会踢人,但问题是我收到此错误

NameError: name 'kick' is not defined

这是代码:

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('@everyone'):
        await kick(message.author,reason = "spam")

client.run('censored for obvious reasons')

我认为这些评论已经提供了很多信息,但无论如何这里有一个可能的解决方案,以防其他人偶然发现这个“错误”。

您的信息不正确,但您已经提供了我们需要的所有信息,只有这些必须在安排中更改。

看看下面的代码:

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('@everyone'):
        await message.author.kick(reason="Spam")
  • 在这里,我们得到message.author并以reason="Spam" kick
  • await kick在这里不起作用,因为机器人不知道踢谁,即使您已经指定message.author作为要踢的人。 这只是错误的安排。

暂无
暂无

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

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