Discord py嵌入不起作用,但在它之前直接发送到频道

huangapple go评论69阅读模式
英文:

Discord py embed not working, but channel send directly before it is

问题

我正在使用Python制作一个Discord机器人我试图将ctx.send更新为返回嵌入式消息而不是简单的消息我的代码如下有趣的是ctx.send有效但然后我的机器人不会直接发送嵌入式消息也不会显示任何错误请注意这是在一个cog内部

另外 - main.check_if_username_used(username) 函数和代码是有效的机器人发送了第一个await ctx.send消息但然后立即失败了下面的嵌入式消息我还尝试了在定义用户名之后使用标题和描述变量进行此操作结果相同

@commands.command()
async def register(self, ctx, name):
    """注册用户"""
    discord_id = ctx.author.id
    username = name

    # 检查discord_id是否已存在
    # 如果是,更新用户名
    # 如果不是,注册新用户
    if main.check_if_username_used(username) > 0:
        await ctx.send("该用户名已经存在,请选择另一个。")
        title = "***小心***"
        description = "该用户名已经存在,请选择另一个。"
        embed = discord.Embed(title=f'{title}', description=f'{description}', color=discord.Color.red)
        await ctx.send(embed=embed)
英文:

I am working on a discord bot in python; i am trying to update my ctx.send to return an embed vs. a simple message. My code is as follows. Interestingly, the ctx.send works but then my bot doesn't send the embed directly below it and shows no errors. Please note this is within a cog.

Also - the main.check_if_username_used(username) function and code WORKS. The bot sends that first await.ctx.send message but then immediately fails the embed below it. I also tried this with the title and description variables after defining username; same thing.

 @commands.command()
    async def register(self, ctx, name):
        """registers a user"""
        discord_id = ctx.author.id
        username = name

            
        # Check if discord_id already exists 
        # If yes, update username
        # If not, register the new user 
        if main.check_if_username_used(username) > 0:
            await ctx.send("That username already exists.  Please select another.")
            title = "***CAUTION***"
            description = "That username already exists.  Please select another."
            embed = discord.Embed(title = f'{title}', description = f'{description}', color = discord.Color.red)
            await ctx.send(embed=embed)

I have tried many different methods of this including simply putting the text in the embed vs an F-String, i have tried creating the embed as a helper function but with that not working i moved to putting it directly into the command.

答案1

得分: 1

应该在 discord.Color.red 后面加上括号,变成 discord.Color.red()

英文:

I missed () after discord.Color.red.

Should be discord.Color.red()

答案2

得分: 0

尝试打开日志记录。

Cog 在异常处理程序就位后加载,因此,您可能遇到的任何错误都将被隐藏。将日志记录级别设置为 DEBUG,您将开始看到所需的消息。

import logging

logging.basicConfig(level=logging.DEBUG)
英文:

Try turning on logging.

The Cog is loaded once Exception handlers are in place, so, any error you may have will be hidden. Turn the logging to DEBUG, and you will start to see the messages you need.

import logging

logging.basicConfig(level=logging.DEBUG)

huangapple
  • 本文由 发表于 2023年3月7日 11:24:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定