基本命令不会突然起作用!不和谐

时间:2020-10-13 20:06:35

标签: python discord bots discord.py discord.py-rewrite

我不知道我做错了什么,改变了什么。突然,我的不一致机器人代码无法正常工作。请帮我。我已经尝试了很多东西,并检查了我的齿轮是否正确加载以及它们是否正确。我也没有任何错误。抱歉,这只是我没有看到的愚蠢错误,因为这是我关于堆栈溢出的第一个问题。

不起作用的命令示例:

@bot.command()
async def test(ctx):
    await ctx.send("help me")

一个无效的齿轮:

#Imports
import discord
from discord.ext import commands
import random
import json
from pathlib import Path

#Current Working Directory
cwd = Path(__file__).parents[1]
cwd = str(cwd)

#Secret
secret_file = json.load(open(cwd+('\secrets.json')))

#Setup
class Basic(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_ready(self):
        print("Bot basic commands are online.\n---------")

    #Greeting
    @commands.command(aliases = ["hello", "hey"], description = "Greets you.")
    async def hi(self, ctx):
        embed = discord.Embed(colour=0x1ABC9C)
        embed.title = "Hey there!"
        embed.description = f"Nice to see you **{ctx.author.mention}**"
        await ctx.send(embed = embed)

#Add Cog
def setup(bot):
   bot.add_cog(Basic(bot))

我是新来的,如果这是一个愚蠢的错误,抱歉。非常感谢!

PS:我很高兴附上更多代码。

编辑:我的主要代码(如果需要)

Imports
import discord
import os
from discord.ext import commands, tasks
import random
import logging
from itertools import cycle
from discord import user
import asyncio
import time
import json
from pathlib import Path

#---------------------------------------------------------------------

#Define a few things...
choice = random.choice
randint = random.randint

#Current Working Directory
cwd = Path(__file__).parents[0]
cwd = str(cwd)

#Json
secret_file = json.load(open(cwd+('\secrets.json'))) #Secrets

#Json Variables
TOKEN = secret_file["token"]

#---------------------------------------------------------------------

#Setup
bot = commands.Bot(command_prefix = "-", case_insensitive = True, owner_id = 567327597642383420)
bot.remove_command('help')

@bot.event
async def on_ready():

    bot.loop.create_task(change_status())

    await asyncio.sleep(0.5)

    print(f'Logged in as: {bot.user.name}\n---------')
    print(f'Id: {bot.user.id}\n---------')
    print(f"Path: {cwd}\n---------")

#----------------------------------------------------------------------------

#Functions

#Change Status
async def change_status():
    await bot.wait_until_ready()

    #Local Variables
    statuses = [f"| By Kwuartz_", "| -help"]
    statusnum = 0

    #Loop
    while not bot.is_closed():

        #StatusNumChanger
        if statusnum == 0:
            statusnum = 1

        else:
            statusnum = 0



        await bot.change_presence(activity = discord.Game(name = statuses[statusnum]))
        await asyncio.sleep(5)
        print("Status Changed!\n---------")

#-------------------------------------------------------------------------

#Cog Setup
for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        filename = filename[:-3]
        bot.load_extension(f'cogs.{filename}')


print("All cogs have been succesfully loaded and will be online shortly\n---------")

@bot.command()
async def test(ctx):
    print("yes")
    await ctx.send("help me")
    print("command called")

#---------------------------------------------------------------------------

#Events
@bot.event
async def on_member_join(member):
    print(f'{member} has joined the server')

@bot.event
async def on_member_remove(member):
    print(f'{member} has left the server')

@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        embed = discord.Embed(colour=0x1ABC9C)
        embed.title = "**Command Error:**"
        embed.description = f":x: **Why this happened:**\nThe command you specified does not exist."
        await ctx.send(embed = embed)

    else:
        raise error

@bot.event
async def on_message(message):
    if bot.user.mentioned_in(message):
        await message.channel.send("You can type `-help` for more info")

#Token
bot.run(TOKEN)

0 个答案:

没有答案