我有一个可返回头或尾的翻转命令,在添加on_message
函数之前,它运行良好。我对SO进行了一些研究,并阅读了文档,并here表示在await bot.process_commands(message)
函数中包含on_message
,但这不能解决问题,并且flip命令仍然不起作用。如果我删除on_message函数,一切都会按预期进行。
bot.py
import discord
from discord.ext import commands
import random
# from app bot user
# click to reveal
TOKEN = 'token_here'
client = commands.Bot(command_prefix = '!')
@client.event
async def on_ready():
print('Bot ready')
@client.command()
async def flip():
flip = random.choice(['heads', 'tails'])
await client.say(flip)
@client.event
async def on_message(message):
if message.content.upper().startswith('N****'):
await client.send_message(message.channel, "Please do not use that word here.")
client.process_commands(message)
@client.event
async def on_member_join(member):
await client.change_presence(game=discord.Game(name='Hi %s' % (member)))
await client.send_message(member, "Hi %s, Welcome to Carson's Discord Server! This server is fairly NSFW at times; you've been warned! Enjoy your stay :)" % (member))
@client.event
async def on_member_remove(member):
await client.change_presence(game=discord.Game(name='Bye %s' % (member)))
client.run(TOKEN)
当我运行脚本时,其他所有内容均正常运行,没有错误。只是命令不起作用。任何见识将不胜感激。
答案 0 :(得分:2)
您需要await
on_message
的最后一行,因为process_commands
是协程。
await client.process_commands(message)
如果您不一致发送!flip
,则应该能够收到适当的回复(heads
或tails
)。