JustPhantom50
JustPhantom50

Reputation: 37

Suggest command not working in discord.py

I'm currently coding a bot in discord.py that does mod commands like kick, etc. I'm trying to make a command that you can suggest something to the server like they make a channel called suggestion-channel, when they do the command it sends it to that channel. I have a command that sends a message to a specific channel for bot suggestions, but that's the closest I've gotten. below is the code that I have for the suggest command in cogs, yes I use command handling.

@commands.command()
async def suggest(self ,ctx , *, suggestion):
    embed = discord.Embed(title=f"Suggestion from {ctx.author.name}", description=suggestion, color=discord.Color.blue())
    embed.set_footer(text=f"Suggestion created by {ctx.author}")
    channel = discord.utils.get(message.server.channels, name="suggestion-channel")
    message = await channel.send(embed=embed)
    await message.add_reaction("✅")
    await message.add_reaction("❌")
    await ctx.message.delete()
    await ctx.send("Thank you for your suggestion!")

Upvotes: 2

Views: 678

Answers (1)

Bagle
Bagle

Reputation: 2346

First of all, you're not getting the channel in an on_message event, or using a user's message to get the server's channels. You'll have to replace message with ctx. Secondly, ctx.server is no longer valid since discord.py's migration. It would now be known as ctx.guild, which you can read about in their docs.

    channel = discord.utils.get(message.server.channels, name="suggestion-channel")
    # change this to:
    channel = discord.utils.get(ctx.guild.channels, name="suggestion-channel")

Changing the code working

Otherwise, if you find that any of your other commands are not working, you may have not processed your on_message event. You can view questions on how to solve this:

Upvotes: 1

Related Questions