gpt4 book ai didi

python - 每当我输入某些命令时,我的机器人就会重复自己(discord.py,Python v3.7)

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:53 24 4
gpt4 key购买 nike

我设置的不和谐机器人一开始运行良好,但现在在命令后重复消息(或发送多条消息)。我不确定如何解决这个问题。

我正在尝试为我所在的不和谐服务器设置一个机器人。工作人员团队知道我经常在网上查看机器人并且我可以编写一些代码。他们问我是否可以为服务器制作一个机器人,所以我决定尝试一下。大约 1.5 小时后,我设置了一个机器人并给了它一些要使用的命令。我尝试在网上搜索解决方案,但找不到任何适合该问题的内容。

这是我的“bot.py”文件中的主要代码。出于显而易见的原因,我在 client.run 中隐藏了 Bot token 。

import discord
import random
import os
from discord.ext import commands

client = commands.Bot(command_prefix = 'pj!')

@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')

client.run('[REDACTED]')

这是我在名为 Alpha.py(临时标题)的 Cog 中的代码。目前,只有 ping 和 help 命令出现问题。

import discord
from discord.ext import commands

class Alpha(commands.Cog):

def __init__(self, client):
self.client = client

@commands.Cog.listener()
async def on_ready(self):
print('Bot: Online')

@commands.command()
async def ping(self, ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)}ms')

@commands.command()
async def _8ball(self, ctx, *, question):
responses = ['It is certain.',
'It is decidedly so.',
'Without a dobut.',
'Yes - definitely.',
'You may rely on it.',
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again later.',
'Better not tell you now.',
'Concentrate and ask again.',
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.']
await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')

def setup(client):
client.add_cog(Alpha(client))

Ping Command对于 ping 命令,我希望它发布一条消息“Pong![latency]ms”一次,其中包含单个值,其中 [latency] 是。相反,它会使用三个不同的值发布消息三次,其中 [latency] 为

Help Command对于帮助命令,我希望它发布一条消息,显示可用的命令。相反,它发送六条消息(有些消息显示所有命令,有些仅显示一两条)。

最佳答案

如果您在 Heroku 或任何其他主机服务上托管此机器人,并且同时在您的 PC 上托管该机器人,它将响应消息两次(如果您托管在更多服务器上,则响应次数甚至更多)。尝试更改机器人的 token 以停止一切。

关于python - 每当我输入某些命令时,我的机器人就会重复自己(discord.py,Python v3.7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com