1

How do I edit the question Why does bot.get_channel() produce NoneType??

Background

I'm trying to get out of a question ban, and I've realized it is futile to edit unsalvageable posts. So, instead, I'm trying to edit posts that can help more people and don't have any downvotes. So, to get upvotes, I've come here.

Why?

Well, partly the meta effect (the positive version), and some pointers to help me fix an "ok" (unless it isn't and is bad or something) post to a decent one.

Why I believe this post has helped people and I should edit it

  1. It's got 1k views
  2. It's been used to flag another post, How to send message to a specific discord channel , as a duplicate

What I've done already

  1. Changed the error to a code block
  2. Given a minimum reproducible example

What more should/can I do to help others (who have the same question) read this question?

2
  • 1
    Not my Area of Expertise, but shouldn't the faulty Line/Command (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 the await channel_id.send(embed = embed_announce) Line as being the one producing the Error...
    – chivracq
    Commented Mar 20, 2023 at 8:27
  • Not all questions on Stack Overflow deserve an answer. Many, especially the beginner-level ones, are blatant duplicates. That is, they are not really questions, but more like search queries (I don't blame the users, as search is broken). The duplicate should be indicated instead. Commented Mar 20, 2023 at 12:38

3 Answers 3

6

I'm not really seeing a problem with that specific question. It's got just about everything we would ask for in a question and it's not asking too much of anything.

5
  • Ah dang. Someone JUST downvoted it. Now I'm just confused as to why...
    – Blue Robin
    Commented Mar 20, 2023 at 1:46
  • 6
    @BlueRobin I guess because you tried to exploit the meta effect by mentioning it in the question...
    – Andrew T.
    Commented Mar 20, 2023 at 3:14
  • @AndrewT. I guess (I was being honest, but maybe I shouldn't have)... But I also just want good pointers. How else am I going to get out of the question ban? Isn't it a bit uncool to vote for something not based on the post, but on the author?
    – Blue Robin
    Commented Mar 20, 2023 at 3:15
  • @AndrewT. There was a higher chance for me to receive downvotes from the meta effect tbh. My past experiences with the meta effect are pretty bad.
    – Blue Robin
    Commented Mar 20, 2023 at 3:17
  • @BlueRobin unfortunately people will always downvote things for whatever reason they want to, best thing to do, is keep doing what you are doing by seeking guidance on providing good content, and ignoring the score on your posts Commented Mar 21, 2023 at 9:16
3

Ask only one question by removing everything that raises other questions.

Right now the question has three separate sub-questions: A "bot.get_channel produces NoneType" part (title and "past attempt"), a "bot gets stuck during announce" (the stack trace and MRE) and "how to get the channel" (the "What I want to do" and end).
The how-to part would not be too severe if paired with the bot.get_channel error (since one is an attempt at the other), but the completely separate errors are definitely too far away.

Since the question already has an answer (for the bot.get_channel part) this is what should be kept. Make sure to add an MRE for this specific issue.

5
  • So I did a clarity edit, and I believe I fixed the problems with the post.
    – Blue Robin
    Commented Mar 22, 2023 at 17:46
  • @BlueRobin I really don’t see what you mean by that. The recent edit only added some imports and a vague instruction how to stitch together two code snippets. This doesn’t address what I write at all - the largest part of the question and the mre are still for a separate error. Commented Mar 22, 2023 at 19:33
  • I'm not sure what to put in the MRE that wouldn't already be implied. I added import statements from the advice of Karl, but other than that, I have no clue. I think I understand what you mean by the sub-questions. Just edited my post. Does this fix the issue?
    – Blue Robin
    Commented Mar 22, 2023 at 20:24
  • The recent change makes the mre good. You still have two errors, though, and it is unclear how the first relates to the second as well as which one is actually produced by the mre. Commented Mar 22, 2023 at 20:28
  • I see now. If I completely remove the stack trace, would it be ok? (I'm not at my PC atm, and might need to add the 2nd stack trace later)
    – Blue Robin
    Commented Mar 22, 2023 at 20:33
1

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 imports, 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?

8
  • With the MRE, do I need to include other statements that are implied like bot.run, intents, instancing bot, and other statements? Thanks! (also I added where the error would have occurred and put where the bot.get_channel(channel_id) would have been.
    – Blue Robin
    Commented Mar 22, 2023 at 14:37
  • Ideally, yes. I don't think there is very much required boilerplate with a Discord bot. On the other hand - some questions where people have problems writing a Discord bot, don't actually require a Discord bot to reproduce the problem. It's at least worth checking, for example, whether the issue you're experiencing is just a logical issue in a calculation you want the bot to do, or a general issue with async. I don't think that applies to your specific case, but is my general advice. Commented Mar 22, 2023 at 21:39
  • I edited the question to include the implied statements. I also followed the advice of MisterMiyagi. Is the post good now? Thanks! This was a good learning experience.
    – Blue Robin
    Commented Mar 22, 2023 at 22:16
  • I added another edit to improve formatting and streamline things - and, again, since now I understand that the problem is with the first embed, we shouldn't have the code to create the second, so I removed that too. As for the question: I see many other similar questions that might be duplicates, but yours is now higher quality, if anything. On the other hand, it doesn't seem like there should actually be a reproducible problem; other questions seem to show people successfully using a string as a channel ID for bot.get_channel. Commented Mar 22, 2023 at 22:28
  • Still unclear to me (not being quite familiar with the API): when you use this command, does the user have to type in the channel ID as part of the command? If not, where does it come from? If so, can you be sure you didn't just typo it when testing the first time? Commented Mar 22, 2023 at 22:30
  • The user does have to type the channel ID with the command, but I didn't have any checks in place. I do know it wasn't a typo because I copy pasted it multiple times and it consistently gave me the error. When I wrote this question, I didn't know about higher-level parameters and making the user put in a certain type with the parameter. That's what I would do nowadays, but before I just worked with certain IDs. So, the parameter would be channel: discord.Option(discord.TextChannel) (If I knew back then).
    – Blue Robin
    Commented Mar 22, 2023 at 23:09
  • (They're type annotations, not "higher-level parameters" which is not a real term.) Commented Mar 23, 2023 at 0:16
  • I didn't know what they were called so I just made something up... But thanks!
    – Blue Robin
    Commented Mar 23, 2023 at 0:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .