英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论