我做了一个DM系统现在可以工作了,但是我的其他命令不起作用。我的代码有错误吗?

问题描述 投票:0回答:1
import discord, os, time, random, string, asyncio, datetime, typing
import config
from discord.ext import commands
from discord import DMChannel

intents = discord.Intents.all()
bot = commands.Bot(command_prefix=';', intents=intents)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Game('Start with ;info !'))
    print("{bot.user.name} is up and runing!")
    print(f"_________________________________")


#Info command

@bot.command()
async def info(ctx):
    embed = discord.Embed(
        colour=discord.Colour.purple(),
        description="Welcome to Infinity.\n\n**What is Infinity?**\n Infinity is a bot that support mental health!\n\n**How dose it help?**\n Infinity helps by being there to cheer you up, and there will always be a support person there to talk to.\n\n**How dose someone talk to you through the bot?**\n The bot uses a DM system where you can DM the bot and it will go to one of our support team members. \n\n **How do I report a bug or someone using the bot?**\n You may use our support server to report bugs or someone who uses the bot.",
        title="Hello, I am Infinity!"
    )
    embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/1142857962172457102/1142891040781635634/Infinity.png")

    await ctx.reply(embed=embed)


#More commands

@bot.command()
async def quote(ctx):
    embed = discord.Embed(
        colour=discord.Colour.purple(),
        description="You're braver than you believe, and stronger than you seem, and smarter than you think",
        title="Quote of the Day!"
    )
    embed.set_footer(text="20/08/23")

    await ctx.reply(embed=embed)

#DM System

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    if str(message.channel.type) == "private":
        dm_channel = discord.utils.get(bot.get_all_channels(), name="dm-system-test")
        await dm_channel.send("[" + message.author.display_name + "]" +  message.content)
    elif str(message.channel) == "dm-system-test" and message.content.startswith("<"):
        member_object = message.mentions[0]

        index = message.content.index(" ")
        string = message.content
        mod_message = string[index:]

        await member_object.send("[" + message.author.display_name + "]" + mod_message)
        
        await bot.process_commands(message)





bot.run(config.TOKEN)

我在发出几个命令后尝试制作一个 DM 系统,然后我测试了 DM 的系统,它可以工作,但我的其他命令却不能。 我在上面发布了我的代码,以便您可以查看它是否有任何错误,这就是我的全部代码,没有其他内容。 (我的令牌有一个单独的配置部分)

python discord.py command
1个回答
0
投票

这行

await bot.process_commands(message)
缩进不正确。 它应该与您的
if message.author == bot.user:
声明处于同一水平。

纠正这个,它应该可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.