gpt4 book ai didi

python - Discord.py - 机器人没有响应

转载 作者:行者123 更新时间:2023-12-04 07:35:32 26 4
gpt4 key购买 nike

我正在 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 中输入信使一个字时 list ,机器人根本没有反应!我将不胜感激所有的帮助!

最佳答案

您需要标记on_message作为一个事件。只需添加 @client.eventasync def on_message(message) 之上它应该工作!编辑:您需要添加 client.process_commands()给您的on_message()以及

关于python - Discord.py - 机器人没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67763401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com