This is not a minimal reproducible example
As explained in https://stackoverflow.com/help/minimal-reproducible-example, we are looking for:
- Minimal: Use as little code as possible that still produces the same problem
- Complete: Provide all parts someone else needs to reproduce your problem in the question itself
- Reproducible: Test the code you're about to provide to make sure it reproduces the problem
That means: if I copy and paste the code from the question into a Python source file and run it, I should directly see the error that is described in the question. This should involve as little action as possible on my part to interact with the code (here, going into the server and typing the appropriate command - the question should explicitly say what to type).
The code should include all necessary import
s, as well as any setup code required to create the bot and make it connect to the Discord server. It should not include anything that is irrelevant to the error. In your case, it looks like the intent of announce
is to send two messages. Does the error occur if you only send the first, or only send the second? Then only show the code for that. Even if it isn't good UI. That can be addressed later, after the problem is dealt with.
Connect the example to the past attempts
I have tried getting the channel with:
I can't make sense of this description, because that code is not anywhere in the code example and there is not an obvious place in that example where it would slot in. Where did you try it? How did you intend for it to help? What would you have done with the result, if there was not an error? For example, were you trying to figure out a channel ID to type when issuing the command on Discord? Then say that. Alternately, did you mean that this is code you tried putting inside the function (so that channel_id
is the parameter)? Then explain: 1) where? 2) For what purpose? I assume that you expected bot.get_channel(channel_id)
to evaluate to some kind of Channel object; but what did you intend to do with that object? How is this intended to help solve the problem?
Ask one question at a time
Like MisterMiyagi said. For example, if you need to know a channel ID in order to use the command properly, and you don't know a channel ID, and there was a problem with the code you tried to use to find out, then ask about that first, by itself. Make sure to show a MRE for that problem, with corresponding error message etc.
Try a bit more debugging first
How much research effort is expected of Stack Overflow users?
It's useful to understand the problem as much as possible before asking a question, in order to make the question as intelligible as possible. print(channel_id)
is a good first step for debugging, but it's also useful to check the type of the channel_id
. I assume that you concluded that you need some kind of Channel object in order to call the send
method, and that you just saw some number. However, did you think to check whether that was an integer or simply a string with digits in it? Did you try reading the documentation, in order to understand what should be passed to bot.get_channel
? Is it expecting a string, an integer, something else?
bot.get_channel(channel_id)
) that triggered your Question be included in your MRE/Code Snippet, (maybe commented out)...? It is only mentioned afterwards (and in the Title) and comes then a bit "out of the blue" and is difficult to "place back" in the Script, while the accepted Sol/Answer (await bot.get_channel(int(channel_id)).send(embed=embed_announce)
) points to theawait channel_id.send(embed = embed_announce)
Line as being the one producing the Error...