[英]Discord.py - bot doesn't respond
我正在 Python 上构建 Discord 机器人,但代码有问题。 这是我的整个代码:
import discord
from discord import message
from discord.ext import commands
client = commands.Bot(command_prefix='_')
gret_words = ['hi', 'grets', 'greetings', 'mornin', 'hey']
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command(pass_context=True)
async def hello(ctx):
author = ctx.message.author
await ctx.send(f'Hello, {author.mention}! My name is Bot-3P0!')
async def on_message(message):
msg = message.content.lower()
if msg in gret_words:
await message.channel.send("Nice to see you!")
####################
client.run('TOKEN')
但我的问题是,当我从gret_words
列表中输入 messenger 一个词时,机器人根本没有反应! 我将不胜感激所有的帮助!
您需要将on_message
标记为事件。 只需在async def on_message(message)
之上添加@client.event
,它应该可以工作:编辑:您还需要将client.process_commands()
添加到您的on_message()
中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.