【发布时间】:2021-11-29 06:23:45
【问题描述】:
所以我想写一个有趣的小不和谐机器人,它以俄罗斯为主题。无论请求什么歌曲,我都想让它播放苏联国歌,在discord命令中“&channel”之后写的频道中。
这是我得到的控制台提要,当我输入“vadim play something &channel Just Chatting blyat:
女贞 只是聊天 忽略 on_menter 代码中的异常 回溯(最近一次通话最后): _run_event 中的文件“C:\Users\maria\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py”,第 343 行 等待 coro(*args, **kwargs) 文件“C:\Users\maria\Desktop\Coding\Projekte\Python\SovjetBot\Code\bot.py”,第 33 行,on_message voicechannel = channel.connect() AttributeError: 'NoneType' 对象没有属性 'connect'
这是我的代码:
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)
【问题讨论】:
标签: python python-3.x discord discord.py