我的python discord机器人发送消息时异常

2024-05-14 14:34:00 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我的目标的基本jist是尝试给我一个可管理的列表,以帮助在discord服务器中组织主题名称。我的代码应该允许我查看列表编辑列表并再次显示。当我的bot试图通过发送更新的列表时,会出现问题。这是我的代码和问题

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

FreeExtras = []

@client.command()
async def Free0(ctx):
    await ctx.send(FreeExtras)

@client.command()
async def addextra(ctx):
    name = await client.wait_for('message',check=lambda m: m.author == ctx.author and m.channel == ctx.channel)
    FreeExtras.append(name)

当我在编辑我的bot后尝试显示列表时,会发送以下消息:

[<Message id=804880602042073118 channel= type=<MessageType.default: 0> author=<Member id=306814779358445570 name='Gundamn' discriminator='0657' bot=False nick=None guild=> flags=>]


Tags: 代码nameimportclient编辑列表asyncbot
1条回答
网友
1楼 · 发布于 2024-05-14 14:34:00

wait_for('message')返回一个Message对象,您需要通过.content附加它的content

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

FreeExtras = []

@client.command()
async def Free0(ctx):
    await ctx.send(FreeExtras)

@client.command()
async def addextra(ctx):
    global FreeExtras
    name = await client.wait_for('message',check=lambda m: m.author == ctx.author and m.channel == ctx.channel)
    FreeExtras.append(name.content)

相关问题 更多 >

    热门问题