我正在使用atom编写python机器人程序,以使其不和谐,并且每当我在机器人程序上运行命令(包括帮助)时,它都会向该命令发送多个响应,但并非所有响应都相同(例如:s?ping它将使用不同的ping多次回答)。我认为它发送的金额是随机的,我不确定它到底出了什么问题,我听说循环可以做到这一点,但是我只有一个循环,那就是改变状态。这是我的代码(没有令牌):
import discord
import random
import os
from itertools import cycle
from discord.ext import commands, tasks
client = commands.Bot(command_prefix = 's?')
status = cycle(['s? // Senkuu by Rubix', 's?help - Made by Rubix#8166', 's? // Alpha v0.11.2, Made in Python (discord.py/atom)'])
@client.event
async def on_ready():
change_status.start()
print( 'Bot is ready. ')
@tasks.loop(seconds=20)
async def change_status ():
await client.change_presence(activity=discord.Game(next(status)))
@client.command()
async def ping(ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)} ms')
@client.event
async def on_command_error(ctx, error):
if isinstance(error,commands.MissingRequiredArgument):
await ctx.send('Missing Requirements in Command, Try Again.')
@client.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
responses = ["It is certain.",
"It is decidedly so.",
"Without a doubt.",
"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.",
"Cannot predict 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)}')
@client.command()
@commands.has_role('Moderator [Staff]')
async def purge(ctx, amount : int):
await ctx.channel.purge(limit=amount)
@client.command()
@commands.has_role('Moderator [Staff]')
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'Banned {member.mention}')
@client.command(pass_context=True)
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, user: discord.User, *, reason):
server = ctx.message.server
mention = user.mention
id = user.id
author = str(ctx.message.author)
x = discord.utils.get(server.channels, name="criminal-records?")
kick_message = "**Type: Kick**\n**User:** " + user.name + "#" + user.discriminator +"(" + id + ")" \
+ "(" + mention+")\n" \
"**Reason:** " + reason +"\n" \
"**Responsible Moderator: **" + author
await self.bot.kick(user)
await self.bot.send_message(x, kick_message)
@client.command()
@commands.has_role('Moderator [Staff]')
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split('#')
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
return
@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]}')```
答案 0 :(得分:0)
我看不出有什么理由让它循环播放。您的齿轮中是否有任何pong命令?我已更正了您的缩进并运行,没有遇到相同的问题。
答案 1 :(得分:0)
我让漫游器多次运行(几天前已修复)