我正在为Discord创建一个机器人,我刚写了这个简单的代码:
import discord
TOKEN = "token"
client = discord.Client()
@client.event
async def on_ready():
print('Bot is ready.')
client.run(TOKEN)
Run Code Online (Sandbox Code Playgroud)
它会产生以下错误:
Traceback (most recent call last):
File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/Main.py", line 1, in <module>
import discord
File "/Users/pcaires/Desktop/Programac?a?o/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "/Users/pcaires/Desktop/Programac?a?o/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/client.py", line 38, in <module>
from .state import ConnectionState
File "/Users/pcaires/Desktop/Programac?a?o/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/state.py", line 36, in <module>
from . import utils, compat
File "/Users/pcaires/Desktop/Programac?a?o/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/compat.py", line 32
create_task = asyncio.async
^
SyntaxError: invalid syntax …Run Code Online (Sandbox Code Playgroud) .
.
.
例如:กิิิิิิิิิิิิิิิิิิิิก้้้้้้้้้้้้้้้้้้้้ก็็็็็็็็็็็็็็็็็็็็ก็็็็็็็็็็็็็็็็็็็็กิิิิิิิิิิิิิิิิิิิิก้้้้้้้้้้้้้้้้้้้้ก็็็็็็็็็็็็็็็็็็็็กิิิิิิิิิิิิิิิิิิิิ ก้้้้้้้้้้้้้้้้้้้้กิิิิิิิิิิิิิิิิิิิิก้้้้้้้้้้้้้้้้้้้้ก็็็็็็็็็็็็็็็็็็็็ก็็็็็็็็็็็็็็็็็็็็กิิิิิิิิิิิิิิิิิิิิก้้้้้้้้้้้้้้้้้้้้ก็็็็็็็็็ ็็็็็็็็็็กิิิิิิิิิิิิิิิิิิิิก้้้้้้้้้้้้้้้้้้้้(或任何"zalgo"文本)
我还没有找到任何方法来检查这些.我正在制作一种反垃圾邮件,我认为不需要保留这些反垃圾邮件,因为它们可能会滞后于用户,而且通常只是垃圾邮件.
我想做的是
if (getMessage().getRawContent().contains(combined character).delete();
Run Code Online (Sandbox Code Playgroud)
如果有人知道检查组合字符的简单方法,请发布!
如果您对我的要求感到困惑,我可以进一步解释,并在需要时显示更多示例.
所以.我正在尝试制作一个不和谐机器人,但我不太了解Discord.js.我的代码看起来像这样:
client.on("message", function(message) {
if(message.content === "ping") {
client.message.send(author, "pong");
}
});
Run Code Online (Sandbox Code Playgroud)
问题是我不太明白如何发送消息.
有谁能够帮我 ?
早上好!
我正在寻找一种通过不和谐机器人流式传输视频的方法,但在文档中找不到任何参考。有什么方法(官方/非官方)可以做到这一点吗?
谢谢你的时间 :)
按照此; https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script
我试图运行node deploy-commands.js将我的命令注册到单个公会,但出现以下错误。
C:\Users\\\\hello-world-discord-bot>node deploy-commands.js
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\\\\\hello-world-discord-bot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\\\\\hello-world-discord-bot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.js:99:20)
at async C:\\\\\hello-world-discord-bot\deploy-commands.js:17:3 {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'put',
url: 'https://discord.com/api/v9/applications/877359061669118003/guilds/447125601757691915/commands'
}
Run Code Online (Sandbox Code Playgroud)
我尝试删除机器人并通过开发人员 Web 控制台重新许可它,然后再重新添加它。我已经检查并重新添加了token clientId和guildId我每次都会收到相同的错误消息。我可以看到它没有获得访问权限,但我不知道还会从哪里授予访问权限。
我的deploy-commands.js看起来像这样:
{
"clientId": "123456789012345678",
"guildId": "876543210987654321",
"token": "my-token-goes-here"
}
Run Code Online (Sandbox Code Playgroud) 我在 Heroku 上托管了一个 Discord 音乐机器人,它似乎无法播放音乐,因为找不到 FFMPEG。这是可以理解的,因为 FFMPEG 仅在我的 PC 中可用,而不能在外部云上使用。我该怎么做才能在 Heroku 上安装 FFMPEG?
我编写了以下代码来记录发送到我的机器人的 DM:
client.on('messageCreate', async message => {
if (message.author.bot) return;
const attachment = message.attachments.first()
if (message.channel.type === 'DM') {
console.log(message.content)
const dmLogEmbed = new MessageEmbed()
.setColor("RANDOM")
.setTitle(`${message.author.tag} dmed the bot and said: `)
.setDescription(message.content)
.setFooter(`User's id: ${message.author.id}`)
if (message.attachments.size !== 0) {
dmLogEmbed.setImage(attachment.url)
}
client.channels.fetch("852220016249798756").then((channel) => {
channel.send({ embeds: [dmLogEmbed] })
})
}
});
Run Code Online (Sandbox Code Playgroud)
但是当更新到discord.js v13时,它不再工作了,据我了解,唯一的变化是“dm”通道类型不再是“dm”而是“DM”,所以我在代码中更改了它,但它仍然不起作用,我真的不知道为什么。
我尝试使用新的 Discord.js 版本编写机器人,但当我尝试登录时,它提示我此错误
/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279
if (!Object.hasOwn(given, key) || given[key] === undefined) {
^
TypeError: Object.hasOwn is not a function
at mergeDefault (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279:17)
at new BaseClient (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/BaseClient.js:25:20)
at new Client (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/Client.js:43:5)
at Object.<anonymous> (/home/max/Schreibtisch/Discord Bots/Perplex/src/bot.js:26:16)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Function.Module._load (node:internal/modules/cjs/loader:828:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
Run Code Online (Sandbox Code Playgroud)
这是我的机器人代码
/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279
if (!Object.hasOwn(given, key) || given[key] === undefined) {
^
TypeError: Object.hasOwn is not a function
at mergeDefault (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279:17)
at …Run Code Online (Sandbox Code Playgroud) 这是我的python程序的相关代码:
import discord
import asyncio
class Bot(discord.Client):
def __init__(self):
super().__init__()
@asyncio.coroutine
def my_background_task(self):
yield from self.wait_until_ready()
while not self.is_closed:
yield from asyncio.sleep(3600*24) # <- This is line 76 where it fails
doSomething()
bot = Bot()
loop = asyncio.get_event_loop()
try:
loop.create_task(bot.my_background_task())
loop.run_until_complete(bot.login('username', 'password'))
loop.run_until_complete(bot.connect())
except Exception:
loop.run_until_complete(bot.close())
finally:
loop.close()
Run Code Online (Sandbox Code Playgroud)
该程序偶尔退出(自己,但不应该),除了以外没有其他错误或警告
Task was destroyed but it is pending!
task: <Task pending coro=<my_background_task() running at bin/discordBot.py:76> wait_for=<Future pending cb=[Task._wakeup()]>>
Run Code Online (Sandbox Code Playgroud)
如何确保程序不会随机退出?我在Xubuntu 15.10上有Python 3.4.3+.
我正在开发一个不和谐的机器人并试图解决这个问题。我想知道如何在非异步函数中使用await ,或者是否可以在代码最后一行的lambda 行中await 函数。
我尝试过使用asyncio.run玩家变量,我asyncio.run_coroutine_threadsafe也尝试过,但没有成功。
关于如何使其发挥作用有什么想法吗?
代码:
def queue_check(self, ctx):
global queue_list
global loop
global playing
if loop is True:
queue_list.append(playing)
elif loop is False:
playing = ''
if ctx.channel.last_message.content == '$skip' or '$s':
return
song = queue_list.pop(0)
player = await YTDLSource.from_url(song, loop=self.client.loop, stream=True)
ctx.voice_client.play(player, after= queue_check(self,ctx))
@commands.command(aliases=['p'])
@commands.guild_only()
async def play(self, ctx, *, url):
global queue_list
global playing
if ctx.voice_client is None:
if ctx.author.voice:
await ctx.author.voice.channel.connect()
else:
return await ctx.send("> You are not connected …Run Code Online (Sandbox Code Playgroud) discord ×10
discord.py ×4
javascript ×4
discord.js ×3
node.js ×2
python-3.x ×2
bots ×1
discord-jda ×1
ffmpeg ×1
heroku ×1
java ×1
python ×1