jxstDex
jxstDex

Reputation: 5

Verification system. (discordpy)

Okay so im trying to make a verify system, but im stuck with it. How could i fix it? (The reason for why i dont use simply ctx, is that this is in an on_ready event.)

    guild = client.get_guild(id)
    if client.fetch_guild(guild) == '928779004654256239':
        channel = client.get_channel('930910261332819968')
        text = discord.Embed(title="React below to verify.", color=discord.colour.blue())
        moji = await client.send_message(channel, text, embed=text)
        await client.add_reaction(moji, emoji='✔')
    else:
        return

Traceback:

C:\Users\User\Desktop\Dexton\Dexton.py:19: RuntimeWarning: coroutine 'Client.fetch_guild' was never awaited if client.fetch_guild(guild) == '928779004654256239'

Upvotes: 0

Views: 258

Answers (1)

metro
metro

Reputation: 508

To answer your question, fetch_guild makes an API call and is a coroutine, so any calls to it should be awaited. It also accepts an int as a parameter, not a Guild, and you probably don't want to be comparing a Guild to an int either.

However, it seems that you're making unnecessary function calls anyway - you shouldn't need to call get_guild or fetch_guild at all. Just calling get_channel should be enough since the return type will be None if your bot account isn't in the guild anyway (as the channel won't be found).

With that in mind, you can change your code as such:

channel = client.get_channel(930910261332819968)
text = discord.Embed(title="React below to verify.", color=discord.Colour.blue())
if channel:
    moji = await channel.send(embed=text)
    await moji.add_reaction('✔')

A few other improvements were also made in the above code snippet, namely using TextChannel.send and Message.add_reaction in favor of Client.send_message and Client.add_reaction, respectively.

You should also keep in mind that a new verification message will be sent each time you run your bot unless you add a mechanism to prevent that. You may also want to use fetch_channel rather than get_channel to prevent any cache issues.

Upvotes: 1

Related Questions