So I want to write a funny little discord bot that's in a russian theme. I want to make it play the USSR Anthem no matter what song is requested, in the channel that's written after "&channel" in the command on discord.
This is the console feed I get, when I type "vadim play something &channel Just Chatting blyat:
Privet Just Chatting Ignoring exception in on_menter code hereessage Traceback (most recent call last): File "C:\Users\maria\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "C:\Users\maria\Desktop\Coding\Projekte\Python\SovjetBot\Code\bot.py", line 33, in on_message voicechannel = channel.connect() AttributeError: 'NoneType' object has no attribute 'connect'
Here's my code:
import discord
from discord.utils import get
import time
class MyClient(discord.Client):
#Triggered on login
async def on_ready(self):
print("Privet")
#Triggered on messages
async def on_message(self, message):
if message.author == client.user:
return
if message.content.lower().startswith("vadim") and message.content.lower().endswith("blyat"):
messagearray = message.content.split(" ")
messagearray.pop()
messagearray.remove("vadim")
if messagearray[0].lower() == "play" and ((len(messagearray)) != 1 or messagearray.contains('&channel')):
where = ""
for i in range(messagearray.index("&channel") + 1, len(messagearray)):
where = where + ' ' + messagearray[i]
where = where[0:]
time.sleep(0.25)
print(where)
channel = get(message.guild.channels, name=where)
time.sleep(0.25)
voicechannel = channel.connect()
time.sleep(0.25)
voicechannel.play(discord.FFmpegPCMAudio('National Anthem of USSR.mp3'))
client = MyClient()
client.run(The bots client id)