如何修复命令不起作用的Discord python机器人

时间:2020-05-14 08:02:06

标签: python bots discord

我的机器人昨天运行良好。我对代码进行了一些更改,当我运行它时,该机器人可以上线,没有任何错误,但是没有命令可以运行。我尝试使用有效的旧代码,但即使该代码也不起作用。我还重新生成了令牌并进行了尝试,但这没有用。请帮忙。

这是我的代码:

import random
import discord
from discord.ext import commands

client = commands.Bot(command_prefix='.')
client.remove_command('help')

TOKEN = ''


# Bot status
@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game('.help for commands!'))
    print("Bot is ready")


# Member join
@client.event
async def on_member_join(member):
    print(f'{member} has joined the server.')
    e = discord.Embed()
    e.set_image(url='https://i.imgur.com/zYexoRK.png')
    channel = discord.utils.get(member.guild.channels, name="welcome")
    await channel.send(f"Welcome {member.mention}! :partying_face:", embed=e)


# Member leave
@client.event
async def on_member_remove(member):
    print(f'{member} has left the server.')



# Ping command
@client.command()
async def ping(ctx):
    await ctx.send(f"Ping is {round(client.latency * 1000)}ms")


# 8ball command
@client.command(aliases=['8ball', 'test'])
async def eball(ctx, *, question):
    responses = ['Absolutely.',
                 'Definitely not.',
                 'It is certain.',
                 'Not at all.',
                 'My sources say no',
                 'Not sure',
                 'Cannot predict now',
                 'Very doubtful',
                 "Don't count on it",
                 'Outlook not so good',
                 'Most likely',
                 'Without a doubt',
                 'As I see it, yes',
                 'You kidding me?',
                 "I don't answer stupid questions.",
                 'Ask again later.',
                 "Yes, but actually no.",
                 "Yes and no.",
                 "I'm no one to decide.",
                 ]
    await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')


# Clear command
@client.command()
async def clear(ctx, amount=5):
    await ctx.channel.purge(limit=amount)


# Help command
@client.command(pass_context=True)
async def help(ctx):
    channel = ctx.message.channel
    embed = discord.Embed(
        title='Commands',
        description='Commands',
        colour=discord.Colour.magenta()

    )

    embed.set_footer(text='@Takahashi | @deviantart.com/seerlight')
    embed.set_image(url='https://i.imgur.com/AVYIGjO.jpg')
    embed.set_thumbnail(url='https://i.pinimg.com/originals/ac/33/cb/ac33cba8c9df761dfcaa31e0e998af47.gif')
    embed.set_author(name='Takahashi', icon_url='https://i.imgur.com/j4SkgMo.png')

    embed.add_field(name='.help', value='Gives this message', inline=False)
    embed.add_field(name='.ping', value='Returns latency', inline=False)
    embed.add_field(name='.8ball', value='Returns answer to your dumb questions', inline=False)
    embed.add_field(name='.clear', value='Clear previous 5 lines', inline=False)
    embed.add_field(name='.flip', value='Randomly gives heads or tails', inline=False)
    embed.add_field(name='.about', value='Information about Takahashi and its developers', inline=False)
    await ctx.send(channel, embed=embed)


# Head and Tails
@client.command(pass_context=True)
async def flip(ctx):
    flip = ['https://i.imgur.com/OqFNJO7.png',
            'https://i.imgur.com/DarGk5i.png', ]
    channel = ctx.message.channel
    embed = discord.Embed(
        title='Heads and tails',
        description='Randomly gives heads and tails',
        colour=discord.Colour.blurple()

    )

    embed.set_image(url=f'{random.choice(flip)}')
    embed.set_thumbnail(url='https://media.tenor.com/images/1dc6f800ad56428f0ac93ae57662a006/tenor.gif')
    embed.set_author(name='Takahashi', icon_url='https://i.imgur.com/j4SkgMo.png')

    await ctx.send(channel, embed=embed)


client.run(TOKEN)

1 个答案:

答案 0 :(得分:0)

应用某些更改后,可能会意外生成 bottoken 或意外删除了caracter,例如DASFRE8894759变为DASFRE884759。区别很难发现。转到不和谐的开发人员门户,然后点击重新生成机器人令牌查看底部并复制粘贴该令牌以确保确定。

希望我能帮助您