问题描述
我正在使用重写创建一个不和谐的机器人,但是当我的命令运行时,它会发送两次消息100% 没有其他调用来发送该消息,并且它只是第一条消息(等等,我正在收集数据),它被发送了两次.这是命令的代码:
I am making a discord bot with the rewrite, but when my command runs, it sends the message twiceThere is 100% no other calls to send that message, and it is only the 1st message(Hold on, I'm gathering the data), that is sent twice.Here is the command's code:
@bot.command()
async def testcmd(ctx):
print("called")
msgtemp = await ctx.message.channel.send("Hold on, I'm gathering the data")
print("sent")
time.sleep(3)
await msgtemp.delete()
with open("fileofthings.txt") as fl:
await ctx.send(fl.read())
推荐答案
我的机器人两次发送响应时遇到了同样的问题,这个特定命令会发生这种情况还是其他命令也会发生这种情况.
I had the same issue with my bot sending responses twice, does this happen with this particular command or it happens with other commands as well.
我的理论是您正在运行 2 个版本的机器人,这意味着您会收到 2 条消息.我开发了一个关机命令,以防再次发生这种情况
My theory is that you are running 2 versions of the bot meaning you get 2 messages. I developed a shutdown command in case this happens to me again
如果您需要,这是我的关机命令代码.
This is my code for a shutdown command if you need it.
@commands.command()
async def shutdown(self,ctx):
if ctx.message.author.id == OWNERID: #replace OWNERID with your user id
print("shutdown")
try:
await self.bot.logout()
except:
print("EnvironmentError")
self.bot.clear()
else:
await ctx.send("You do not own this bot!")
这篇关于机器人两次执行相同的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!