我在用discord.py制作机器人时遇到了一个问题,我设法让命令和on_message一起工作,这有点困难,但是现在所有的命令都可以工作了,但是如果我触发其中一个on_message函数,它就会无缘无故地循环输出。我不确定如何解决这个问题,也不确定它。
import discord
from discord.ext import commands
import random
import os
import time
import typing
bot = commands.Bot(command_prefix = '!')
@bot.command()
async de
我想从他们的Id中得到一个用户的昵称。我有以下代码:
id = 235088799074484224 # User Id
member2 = bot.guilds[guild_id].get_member(id)
print(member2.nick)
但是代码给出了一个错误:
Traceback (most recent call last):
File "C:\Users\Vlad\PycharmProjects\untitled\venv\lib\site-packages\discord\client.py", line 333, in _run_event
我现在正试图为不和创造一个机器人。由于某种原因,令牌给了我这个错误:
2022-11-02 04:42:10 INFO discord.client logging in using static token
Traceback (most recent call last):
File "main.py", line 26, in <module>
client.run(os.getenv("bot_key"))
File "/home/runner/discord-moni-bot-thing/venv/lib/p
因此,我正在制作一个机器人,如果您发送任何有.com的信息,它将删除该消息,并发送一条消息,上面写着“您的消息包含一个链接”,但机器人不起作用。我尝试了很多不同的方法,但仍然无法使它发挥作用!
#--- blacklisted words ---
@bot.event
async def on_message(message):
links = [
".com"
]
if any(word in message.content.lower() for word in links):
await message.delete()
await
from discord.ext import commands
from discord.ext import tasks
import random
import typing
from discord import Status
from discord import Activity, ActivityType
from discord import Member
from discord.ext.commands import Bot
from asyncio import sleep
intents = discord.Intents()
intents.members =
亲爱的社区,我尽了最大的努力,但我不知道为什么机器人只对dm消息做出反应。昨天晚上,这位机器人在fin上工作,并对消息做出了不一致的反应,但现在他只对dm做出反应。这段代码只是我正在使用的on_message函数的一个简短例子,但我找不到替代on_message的方法。
from timeit import repeat
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
from datetime import datetime
import t
所以我创造了一个不和谐的机器人,一切都很好,直到我试图做出一个踢的命令。什么都没用。我上传了一个备份,它仍然不能工作,即使它是一个旧版本。下面是它在外壳中的意思:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 29, in
在discord.py重写中,我试图建立一个投票系统。投票可能需要空间,比如
!vote do this option or do that option
所以我想和同一个用户获得两条消息。
起初,我使用了@client.commmands(),但我认为使用on_message会更好,但任何一个都可以。
我在想这个,
@client.event
async def on_message(ctx): #We only get ctx because it can contain spaces
userid = ctx.author.id
@client.event
我已经和discord.py合作过一段时间,但这种情况从来没有发生过。几乎相同的事情甚至在早些时候以一种稍微不同的方式工作,所以,是的,看看吧: async def on_ready(self):
global BotCommandsChannel
BotCommandsChannel = await self.fetch_channel(838442070326247496)
await BotCommandsChannel.send("Der Bot hat restarted und ist jetzt wieder on
它一次只显示其中一个命令。
如果我写!hi或!bye,它不会工作,但如果我写!sing,它将输出la la la。
如果我切换前面的字符,它会变成!hi或!sing不起作用,但!bye起作用并说Goodbye!
import os
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'
.format(client))
@client.event
async def on_message(message):
if m