我在不和谐(discord.py,PYTHON)中有一个非常强大的机器人,它可以在语音通道中播放音乐。它从 youtube (youtube_dl) 获取音乐。以前它工作得很好,但现在它不想处理任何视频。我尝试更新 youtube_dl 但它仍然不起作用我到处搜索但我仍然找不到可能对我有帮助的答案。
这是错误:Error: Unable to extract uploader id
错误日志之后和之前没有更多信息。有人可以帮忙吗?
我将留下一些用于我的机器人的代码... youtube 设置:
youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0', # bind to ipv4 since ipv6 addresses cause issues sometimes
}
ffmpeg_options = {
'options': '-vn',
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = …Run Code Online (Sandbox Code Playgroud) 昨天,我的代码非常好。一切都在运行……而且进展顺利。突然出现这个错误:
TypeError: __new__() got an unexpected keyword argument 'deny_new'
Run Code Online (Sandbox Code Playgroud)
在我的 PyCharm 控制台中弹出。我在互联网上查过它,但我只找到了一个类似的问题,但答案为零。我希望 stackoverflow 社区能够帮助我。我没有更改我的代码,我所做的只是尝试在 heroku 上托管我的机器人,但进展并不顺利。在我最初的几次尝试之后,我放弃了。但是,我发现我的机器人开始发疯了,我无法再运行它了:<。有没有其他人经历过这个并知道如何解决它? 更新 我刚刚发现由于某种原因,它只能在我的测试服务器上运行,而不能在任何其他服务器上运行。
Traceback (most recent call last):
File "C:/Users/danie/PyCharmProjects/skybot/skybotgaming.py", line 21, in <module>
client.run('TOKEN')
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 640, in run
return future.result()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 621, in runner
await self.start(*args, **kwargs)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 499, in connect
await self._connect()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 463, in _connect
await self.ws.poll_event()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\gateway.py", line 471, in poll_event
await self.received_message(msg)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python编写discord机器人,我遇到了这个机器人.
import discord
import asyncio
import random
client = discord.Client()
inEmail = input("Email:")
inPassword = input("Passwd:")
async def background_loop():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel("************")
messages = ["Hello!", "How are you doing?", "Testing!!"]
await client.send_message(channel, random.choice(messages))
await asyncio.sleep(120)
client.loop.create_task(background_loop())
client.run(inEmail, inPassword)
Run Code Online (Sandbox Code Playgroud)
然而,当我试图运行它时,我收到了SyntaxError:
File "1.py", line 7
async def background_loop():
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是为什么?我测试之前从未收到过.
我正在尝试用python设置一个discord bot.我有一个预先存在的discord服务器,我希望机器人加入,但我很难这样做.
import discord
import asyncio
import logging
logging.basicConfig(level=logging.INFO)
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
print(client)
@client.event
async def on_message(message):
print(message)
if message.content.startswith('!test'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=100):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send_message(message.channel, 'Done sleeping')
client.run('token')
Run Code Online (Sandbox Code Playgroud)
这基本上是GitHub页面上给出的基本discord.py脚本.但是,我似乎无法弄清楚如何让它实际加入我的服务器.将此行插入on_ready函数时:
server = await client.accept_invite('instant-invite-code')
Run Code Online (Sandbox Code Playgroud)
将"即时邀请代码"替换为我的实际即时邀请代码(我尝试了discord.gg/code和代码),我得到了
discord.errors.Forbidden: FORBIDDEN (status code: 403): …Run Code Online (Sandbox Code Playgroud) 我开始学习discord.js,但现在我面临这个问题。我尝试了一些谷歌搜索,但无法修复它。
const Discord = require('discord.js');
// const Discord = require('discord.js');
// Using Intents class
const client = new Discord.Client();
client.on('message', (msg) => {
// Send back a reply when the specific command has been written by a user.
if (msg.content === '!hello') {
msg.reply('Hello, World!');
}
});
client.login('my_token');
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
我正在尝试使用 discord.py 创建斜杠命令,我已经尝试了很多东西,但它似乎不起作用。如有帮助,将不胜感激。
在discord v14中,我尝试使用该messageCreate事件,但是,当用户在discord中键入消息后,message.content没有任何数据,如下所示:
Message {
channelId: '998889338475655188',
guildId: '948995127148425246',
id: '998925735668498433',
createdTimestamp: 1658232854526,
type: 0,
system: false,
content: '',
author: User
Run Code Online (Sandbox Code Playgroud)
我尝试四处搜索,但找不到任何解决该问题的方法,我使用的与不和谐相关的代码是:
import { Client, GatewayIntentBits, Partials } from "discord.js";
const bot = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages
],
'partials': [Partials.Channel]
});
bot.on('messageCreate', async (message) => {
console.log(message);
});
bot.login(process.env.token1)
Run Code Online (Sandbox Code Playgroud)
有谁知道新更新出了什么问题或需要更改什么?
最近,discord 为您自己的应用程序添加了对斜杠命令的支持。我通读了它的文档,并尝试搜索了一些视频(但是该功能刚刚发布),但我不明白我实际上需要做什么才能使其正常工作。我正在使用 WebStorm(js、node.js)。有没有人成功制作过斜线命令,如果有,如何制作?
import discord
import openai
import os
openai.api_key = os.environ.get("OPENAI_API_KEY")
#Specify the intent
intents = discord.Intents.default()
intents.members = True
#Create Client
client = discord.Client(intents=intents)
async def generate_response(message):
prompt = f"{message.author.name}: {message.content}\nAI:"
response = openai.Completion.create(
engine="gpt-3.5-turbo",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
return response.choices[0].text.strip()
@client.event
async def on_ready():
print(f"We have logged in as {client.user}")
@client.event
async def on_message(message):
if message.author == client.user:
return
response = await generate_response(message)
await message.channel.send(response)
discord_token = 'DiscordToken'
client.start(discord_token)
Run Code Online (Sandbox Code Playgroud)
我尝试使用不同的方式来访问 API 密钥,包括添加到环境变量。
我还能尝试什么或者哪里出错了,对于编程来说还很陌生。错误信息:
openai.error.AuthenticationError:未提供 API 密钥。您可以使用“openai.api_key =”在代码中设置 API …
我的代码已经运行了几个星期,但一些事件和函数随机停止工作!
首先, my guildMemberAdd, guildMemberRemove, 和guildMemberUpdateevents 只是停止做任何事情。没有出现错误,当我调试我的代码时,我意识到在发生相应的操作时甚至没有发出事件。
// const client = new Discord.Client();
client.on('guildMemberAdd', (member) => // not triggering!
client.channels.cache.get('channel-id').send(`${member.tag} joined!`); // not sending!
Run Code Online (Sandbox Code Playgroud)
其次,当试图从GuildMemberManager缓存中获取成员时,它总是返回undefined:
const member = message.guild.members.cache.get(targetID); // undefined
Run Code Online (Sandbox Code Playgroud)
当我尝试显示该公会成员缓存中的每个成员时,它只显示了我和我的机器人,而不是通常的 100 多个成员。
然后我尝试使用以下方法获取公会中的每个成员GuildMemberManager.fetch():
const members = await message.guild.members.fetch();
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误:
[GUILD_MEMBERS_TIMEOUT]:成员没有及时到达。
同样,我确定我的语法是正确的,因为它已经完美运行了一段时间,而且我最近没有更新任何会影响此代码的内容。
discord ×10
python ×6
discord.js ×4
discord.py ×4
javascript ×4
node.js ×2
async-await ×1
chatgpt-api ×1
ffmpeg ×1
openai-api ×1
python-3.x ×1
syntax ×1
youtube-dl ×1