我刚刚开始学习如何在discord.py中编写自己的机器人。但是,我遵循了YouTube上的教程,使用了完全相同的代码,但是在我的服务器上不起作用。
import discord from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.command(pass_context = True)
async def test(ctx):
await ctx.send('Pong!')
@client.event
async def on_ready():
print('Bot is ready')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('hello'):
await message.channel.send('Hello there.')
@client.event
async def on_member_join(member):
print(f'{member}has joined the server!!')
@client.event
async def on_member_remove(member):
print(f'Seeya,{member}. Oh wait\n can we?')
client.run('NzU1MjI2Mzk1MjM5Nzc2Mjg2.XGGNZA.s2qLVQMONMLqs1f8Zky9wtM6ZDo')
答案 0 :(得分:0)
覆盖提供的默认on_message
禁止运行任何其他命令。要解决此问题,请在client.process_commands(message)
的末尾添加on_message
行。
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('hello'):
await message.channel.send('Hello there.')
await client.process_commands(message)