【问题标题】:Discord.py bot not sending the whole messageDiscord.py 机器人未发送整个消息
【发布时间】:2020-11-04 05:07:14
【问题描述】:

我有一个不和谐的机器人,当我输入 .members 时,它会返回所有成员 ID 列表。

这是我的代码:

mainbot = commands.Bot(command_prefix = ".")

@mainbot.command()
@commands.guild_only()
async def member(ctx):
    for members in ctx.guild.members:
        ids = members.id

    await ctx.channel.send(ids)

mainbot.run(token_test)

但是,它不会发回所有 ID。相反,它会发回列表中的最后一个 id。

我做错了什么? Python 3.8

【问题讨论】:

  • 你可以在一行中完成:ids = ", ".join([member.id for member in ctx.guild.members])

标签: python discord.py


【解决方案1】:

您的命令总是重写 id。您应该将 ids 设为字符串,然后添加每个成员的 id:

mainbot = commands.Bot(command_prefix = ".")

@mainbot.command()
@commands.guild_only()
async def member(ctx):
    ids = ''
    for members in ctx.guild.members:
        ids += '{}, '.format(members.id)               # += is the change

    await ctx.channel.send(ids)

mainbot.run(token_test)

【讨论】:

  • 非常感谢。
  • 嘿,我们都会犯错。我通常让他们~~moar~~更多的时候。
猜你喜欢
  • 1970-01-01
  • 2020-10-10
  • 2022-01-03
  • 2021-10-14
  • 2021-01-26
  • 2020-12-26
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
相关资源
最近更新 更多