when I am trying to send a message to a channel it won't work. Anyone knows why?
This here is the command I am using. This is just the code block of the not working section.
@bot.command(pass_context=True)
async def test2(ctx):
await ctx.message.delete()
print("The Test is being started")
Channel = config['bot']['id1']
await Channel.send("test2")
And in My Config file, I have this
[bot]
id1= 916845047CENSORED
And when I try to run it I get this error:
The test is being started
Ignoring exception in command test2:
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:/Users/jp/Desktop/DISCORD BOT/bot.py", line 224, in test2
await Channel.send("test2")
AttributeError: 'str' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'send'
If anyone knows how to fix this I would thank you very much
Edit:
The way to solve this is:
add the int to the channel ID if it is from a txt file/config
@bot.command(pass_context=True)
async def test2(ctx):
await ctx.message.delete()
Channel_Id = config['bot']['id1']
print("Test is being started")
Chanel = bot.get_channel(int(Channel_Id))
await Chanel.send("test2")