如何在Discord.py中设置一个不带前缀的命令,该命令仅包含bot回复的特定单词,并且bot仅在dm with bot中回复thaat
如何在Discord.py中设置一个不带前缀的命令,该命令仅包含bot回复的特定单词,并且bot仅在dm with bot中回复thaat,discord.py,Discord.py,Discord.py,如何设置命令,不带前缀,仅使用bot回复的特定单词,以及bot回复该命令,而Dm使用bot 记住错误,例如,bot对象在消息上没有属性,等等,错误。如果在cog中使用此属性 @commands.Cog.listener() async def on_message(self,message): await message.send("Hello!") 或者主要是 @bot.event async def on_message(message): await
Discord.py
,如何设置命令,不带前缀,仅使用bot回复的特定单词,以及bot回复该命令,而Dm
使用bot
记住错误,例如,bot对象在消息上没有属性
,等等,错误。如果在cog中使用此属性
@commands.Cog.listener()
async def on_message(self,message):
await message.send("Hello!")
或者主要是
@bot.event
async def on_message(message):
await message.send("Hello!")
如果您对此有错误,请回复
message.guild
如果邮件在dms中,将返回None。您可以编写一个函数传递到该函数,该函数将检查服务器中的一个前缀和私人邮件中的另一个前缀(或无前缀):
from discord.ext import commands
def command_prefix(bot, message):
if message.guild is None:
return ''
else:
return '$'
bot = commands.Bot(command_prefix=command_prefix)
@bot.command(name='hello')
async def hello(ctx):
await ctx.send("Hello")
bot.run("TOKEN")
你能举几个例子说明机器人会响应什么样的消息以及响应是什么吗?我的意思是,如果任何用户使用一个命令,例如$hello,bot将对该用户进行dm,现在我想发出一些没有前缀的命令,例如hello
,bot只在用户不在服务器上的情况下在dm中响应这些类型的命令,感谢它的工作。但是你能告诉我机器人每n秒发送一条消息的代码吗。要激活另一个botSee,请参阅It's in cog上的示例。关于bot.py或main.py,我看到了Rapptz GitHub后台任务脚本,但如何激活bot以连续发送消息,请向我发送完整代码