我有这个问题,我想将输入作为命令,因此用户键入 !ping
并且我的前缀是 !
,但由于某种原因它不指向:
@client.command()
async def ping(ctx):
print("Someone asked for their latency")
出于某种原因,它指向:
@client.event
async def on_message(message):
print("Someone send a message")
我希望当用户输入 !ping
时,它会将其定向到 ping(ctx)
而不是 on_message(message)
就像它做的不对。这是我的完整代码:
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix="!", intents=intents)
@client.event
async def on_ready():
print("I am ready")
@client.event
async def on_member_join(member):
join_embed = discord.Embed(title=f'{member.name} Joined :)',
description=f"Hey {member.name} remember that addison is weird", colour=16366985)
join_embed.set_image(url="https://www.desicomments.com/wp-content/uploads/2017/07/Hi.gif")
await member.guild.system_channel.send(content=None, embed=join_embed)
print("joined")
@client.event
async def on_member_remove(member):
left_embed = discord.Embed(title=f'{member.name} Left :(',
description=f"Bye Bye {member.name}", colour=16726802)
left_embed.set_image(url="http://www.reactiongifs.com/wp-content/uploads/2012/12/byebye.gif")
await member.guild.system_channel.send(content=None, embed=left_embed)
print("left")
@client.event
async def on_message(message):
print("Someone sent a message")
@client.command()
async def ping(ctx):
print("Someone asked for their latency")
client.run('hajslkdhasjlkdhjwheq')
答案 0 :(得分:1)
您只需在 await client.process_commands(message)
的最后一行添加 on_message()
即可解决此问题