每当我运行命令时,它都会从字面上响应文本,而不是嵌入文本。这是我的代码:
@client.command()
async def item(ctx):
items = [
'embed = discord.Embed(title = "embed1", description = "test1")',
'embed = discord.Embed(title = "embed2", description = "test2")']
randomitem = random.choice(items)
await ctx.send (randomitem)
答案 0 :(得分:0)
尝试一下:
@client.command()
async def item(ctx):
items = [
discord.Embed(title = "embed1", description = "test1"),
discord.Embed(title = "embed2", description = "test2")]
randomitem = random.choice(items)
await ctx.send(embed=randomitem) # embed= - for send discord.Embed
答案 1 :(得分:0)
items
列表中填充了字符串,而不是实际的嵌入对象。
因此要获得所需的结果,您需要像这样删除嵌入对象周围的引号:
items = [ embed = discord.Embed(title = "embed1", description = "test1"),
embed = discord.Embed(title = "embed2", description = "test2")]
由于引号,Python只是将它们视为字符串。
编写代码的更好方法是
items = [discord.Embed(title = "embed1", description = "test1"),
discord.Embed(title = "embed2", description = "test2")]
return ctx.send(embed=random.choice(items))