【发布时间】:2020-11-27 23:33:04
【问题描述】:
如何处理 discord.py 中的所有私人消息? 我想知道是否有办法对所有私人消息回复相同的消息,例如“你不能在私人消息中使用命令” 我知道当消息是私有的时函数会引发错误,但我不想使用 try 并且除了每个函数
如果只有help命令可以私下使用会更好
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite
如何处理 discord.py 中的所有私人消息? 我想知道是否有办法对所有私人消息回复相同的消息,例如“你不能在私人消息中使用命令” 我知道当消息是私有的时函数会引发错误,但我不想使用 try 并且除了每个函数
如果只有help命令可以私下使用会更好
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite
如果需要,请将客户端替换为机器人
@client.event
async def on_message(message):
if message.author.id != client.user.id:
if message.guild: # If message in guild
await client.process_commands(message) # Process command
else:
return await message.author.send("Sorry, but i dont process commands on direct messages...")
【讨论】:
如果你使用discord.ext.commands,你可以用这个开始
@bot.command()
@commands.guild_only()
async def something(ctx):
......
关于帮助命令,您可以让他在服务器中键入命令并私下将其返回给他。这将增加对 ✅ 的反应,并私下向他发送所有帮助的嵌入
bot.remove_command("help")
@bot.command()
async def help(ctx):
embed = discord.Embed(
title="Help")
embed.set_footer(
text="Enjoy, in case of issues contact AZ#0573")
await ctx.author.send(embed=embed)
await ctx.message.add_reaction("✅")
【讨论】: