我希望机器人在成员停止玩游戏后移除角色。
当会员不玩游戏时,就没有game = [i for i in after.activities if str(i.type) == "ActivityType.playing"]了。因此,当尝试删除角色时,我认为它找不到game[0].name。
我该怎么解决这个问题?
@client.event
async def on_member_update(before, after):
game = [i for i in after.activities if str(i.type) == "ActivityType.pl
我想在我的discord机器人中实现一个函数,该函数检查是否有任何成员离线,然后执行以下函数。我已经阅读了API参考页面,但不太理解如何做,像这样的东西可以工作吗?
client = discord.Client()
@client.event
async def on_member_update(before, after):
if before == online:
if after == offline:
print("{} has gone offline.".format(member))
我认为代码不会像预期的那样工
我已经搜索了几个小时的堆栈溢出问题,似乎找不出我哪里错了。我正在尝试制作一个不一致的机器人,在用户获得“已验证”角色后,删除“新手”角色。
@client.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
newRole = next(role for role in after.roles if role not in before.roles)
member = after.name
currentR
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 =
我过去经常在没有代码问题的副本上运行这个机器人,但是在它删除了一些JSON文件并禁用了API之后,我切换到通过VSCode在我的PC上运行它。所有功能都能正常工作,除非它不再从on_member_update获得任何响应。我没有在这里更改任何代码,并确保我的所有意图也得到了排序。有什么想法吗?
import os
from os import path
import discord
import asyncio
from datetime import datetime, date
from pytz import timezone
from keep_alive import keep_al
async def on_message(message):
if message.content.startswith("-test"):
await message.channel.send("Checking for the Status :pencil:..")
time.sleep(1)
async def on_member_update(before, after):
if str("discord.gg / discord") in member.
我正在用python编写一个不和谐的机器人代码,我遇到了一个问题。我希望机器人打印它接收到的消息,但是,它会执行两次。我完全搞不懂它为什么要印两次。
上面是一个链接到导致问题的3个“模块”,它仍在进行中,没有那么多的代码,应该是相当容易浏览。任何帮助,为什么它打印它两次是非常感谢!
Main.py
import discord
import asyncio
from discord import Status
from Status import Member_Status
from User import User_Who
from Matchmaking import MM
runt
我在试着制造一个机器人,当有人在玩游戏的时候,它会扮演一个角色。例如,有人扮演CSGO,机器人会在游戏中给他CSGO角色。我好像搞不懂。
@client.event
async def on_member_update(before, after):
if after.activity != before.activity:
role = discord.utils.get(after.guild.roles, name=after.activity)
if role == None:
await create_role(name
我正在尝试为我的discord机器人写一段代码,当我的一个朋友的个人资料状态从离线更新到在线时,它会发出通知。 目前,我正在摆弄一些代码,这是我到目前为止所拥有的: @client.event
async def on_member_update(before, after)
if str(before.status) == "offline":
if str(after.status) == "online":
await message.channel.send(f"""{} is n
我试图让我的机器人在用户对消息做出反应之后给出一个角色,但是每次我收到相同的错误时。我不明白这个错误意味着什么。有人能帮忙吗?这是代码:
import discord
from discord.ext import commands
from discord import Member
from discord.ext.commands import has_permissions
from discord.ext import tasks
#sets the command prefix
Client = commands.Bot(command_prefix = "!"
当用户的状态发生变化时,我试图让我的机器人列表。当某个人的不和谐状态发生变化时,它应该做的是在某个渠道发送信息。但是,我经常收到以下错误消息:
Traceback (most recent call last):
File "main.py", line 9, in <module>
cmdEXE.all(token)
File "/home/runner/Geek-Bot/Commands/cmdEXE.py", line 9, in all
async def on_member_update(before, after)
每当我尝试使用这个循环功能时,它都会给我一个错误,它的行比我的代码末尾更远。一般来说,我对python和编码是相当陌生的,但我认为这是我下载的存储库的一部分。错误代码如下所示 Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 603, in run
self._do_run()
File "/opt/virtualenvs/python3/lib/python3.8/