python - Discord Bot 不加入语音聊天 (Python)
问题描述
我没有收到任何错误代码,并且每当我将命令 !join 加入聊天时都没有任何反应。我到处搜索,似乎代码应该是正确的。(顺便说一句,我的代码中确实有我的机器人令牌)
import os
import discord
from discord.ext import commands
my_secret = os.environ['Token']
client = discord.Client()
bot = commands.Bot(command_prefix="!")
@client.event
async def on_ready():
print ('{0.user} Activated'.format(client))
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel.id
await channel.connect()
client.run(my_secret)
解决方案
首先,使用commands.Bot
或discord.Client
。不要同时使用它们。Bot
有event
和command
。
import os
import discord
from discord.ext import commands
my_secret = os.environ['Token']
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print ('{0.user} Activated'.format(client))
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
bot.run(my_secret)
推荐阅读
- r - 作为因变量的潜在类
- c# - 洪水填充算法导致 OutOfMemory 异常
- angular - Angular 6 Karma Test '@input 装饰器
- php - 在 Laravel 中提交表单并将内容类型设置为 application/json
- javascript - 如何使用javascript从对象中删除重复项
- python - OAuth 2 身份验证库。如何访问资源?
- vba - 如何在书签前添加内容控件?
- database - HyperSQL Server 2.4.1 在运行时创建新数据库
- list - 将对象添加到 SimpleListProperty
- android - 将 C 源文件交叉编译到 Android Arm