Kemal
Kemal

Reputation: 37

Discord.py bot not sending the whole message

I have a discord bot that when I enter .members, it answers back with all the list of member ids.

This is my code:

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)

However, it doesn't send back all the ids. Instead, it sends back the last id in the list.

What I'm I doing wrong? Python 3.8

Upvotes: 0

Views: 180

Answers (1)

Stick-Figure
Stick-Figure

Reputation: 95

Your command always rewrites ids. You should make ids a string, and then add each member's 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)

Upvotes: 1

Related Questions