2

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!")
JustPhantom50
  • 37
  • 1
  • 5
  • hi, interesting, was there an error? – jspcal Jun 12 '21 at 01:56
  • no errors, it doesn't send anything – JustPhantom50 Jun 12 '21 at 01:59
  • I’m a bit confused about what you’re trying to figure out. Is the current code not working somehow, are you trying to figure out what to do next? Please elaborate. – StarbuckBarista Jun 12 '21 at 02:08
  • @StarbuckBarista im trying to make a command where you type 'm.suggest [message]'. it will then send the suggestion to another channel in there server with the suggestion so the mods can read it and make the fix in the server. I hope this helps. – JustPhantom50 Jun 12 '21 at 02:13
  • Alright, so is the command just not calling? – StarbuckBarista Jun 12 '21 at 02:17
  • yes, no errors and its not sending anything back when the command is done. – JustPhantom50 Jun 12 '21 at 02:20
  • you could at least use `print()` to see which line of code is execute and what you have in variables. It is called `"print debuging"`. – furas Jun 12 '21 at 02:22
  • you could create minimal working code with your problem - and then we can copy it, run it and test ideas. You use `cog` so we should see how you use it. Maybe problem is in different place. – furas Jun 12 '21 at 02:24
  • ok so if i delete `channel = discord.utils.get(message.server.channels, name="suggestion-channel")` the command works but with it, it doesn't not – JustPhantom50 Jun 12 '21 at 02:28
  • don't you get any error message when you run it in console/terminal? In `discord.utils.get()` you use `message` which you get in next line `message = ...` so you have it in wrong order. First `message = ...`, next `discord.utils.get(message, ...)` OR maybe you should use `ctx` or `ctx.message` instead of `message` in `discord.utils.get(...)` – furas Jun 12 '21 at 02:46
  • no, no errors pop up in the console and I'm using error handling so like the command not found stuff. Nothing pops up. also, your saying to switch things up like `server.channels.message`? not sure what your saying. – JustPhantom50 Jun 12 '21 at 02:49
  • in `discord.utils.get(...)` you use variable `message` which doesn't exist. Maybe it should be `discord.utils.get(ctx.server.channels, ...)` or `discord.utils.get( ctx.message.server.channels, ...)`. I can't test it. – furas Jun 12 '21 at 02:50
  • no, none of them work – JustPhantom50 Jun 12 '21 at 02:57
  • Use `ctx.guild` instead of `ctx.server`, which is deprecated in newer versions of discord.py. Other than that, you should be able to send the message to your suggestion-channel successfully. – Bagle Jun 12 '21 at 04:00

1 Answers1

1

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:

Bagle
  • 2,326
  • 3
  • 12
  • 36
  • @JustPhantom50 If my answer answered your question, don't forget to mark this as the accepted answer by using the _green_ tick under the upvote and downvote of this answer. – Bagle Jun 14 '21 at 00:05