Search code examples
pythondiscord

client.fetch_channel() returns AttributeError: '_MissingSentinel' object has no attribute 'is_set'


I want to send a message to a specific channel. I get the channel, but when I try to send a message it makes this error:

Traceback (most recent call last):
  File "C:\Users\nikit\PycharmProjects\Phantom_Shop\discord\ui\view.py", line 425, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\nikit\PycharmProjects\Phantom_Shop\temporary_classes.py", line 200, in buy_callback
    await channel.send("Test")
AttributeError: 'NoneType' object has no attribute 'send'

I am doing this in a separate file(specifically in a button callback in a View) Here's the part of separate file that is used:

from temporary_bot import client
channel = client.get_channel(channel_id)
await channel.send("Test")

and here's the main file:

client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

channel = client.get_channel(***)

@client.event
async def on_ready():
    await tree.sync()
    print('We have logged in as {0.user} bot'.format(client))


@tree.command(name = "start", description = "Start the bot")
async def first_command(interaction):
    view = Menu_View()
    view.add_item(url)
    keys = data["profiles"]

    if f"{interaction.user}" in keys:
        print("Account already in database")
    else:
        data["profiles"][f"{interaction.user}"] = {}
        data["profiles"][f"{interaction.user}"]["balance"] = 0
        print("This is bullshit")
        data["profiles"][f"{interaction.user}"]["spent"] = 0
        data["profiles"][f"{interaction.user}"]["bought_product"] = 0
    with open("profiles.json", "w") as file:
        json.dump(data, file)
    menu = make_menu(interaction.user.avatar)
    await interaction.response.send_message(embed=menu, view=view)

if __name__ == "__main__":
    client.run(TOKEN)

I tried creating the variable in the main file but it made the same error. I use a number as my channel id and I tried it with other channels, same thing.


Solution

  • I just fixed the problem by creating the channel variable in a third file, then editing it in the on_ready function, and finally importing it in the classes file