【发布时间】:2020-12-05 04:05:39
【问题描述】:
我正在尝试创建一个机器人来运行我的个人 discord 帐户,并在人们加入我所在的特定 discord 服务器时直接向他们发送消息。但是,当成员加入服务器时,我的 on_member_join(member) 方法没有运行(不在终端打印“已注册”)。我很好奇如何让机器人监听特定的服务器,或者一般只注册这个事件。注意 on_connect() 和 spam() 都可以正常工作。
import discord
import asyncio
import requests
from discord.ext import commands
yer=commands.Bot(command_prefix="!",help_command=None,self_bot=True)
token="TOKEN"
class SelfBot(commands.Cog):
def __init__(self,yer):
self.yer=yer
@yer.command()
async def spam(ctx):
for i in range(50):
await ctx.send("Hello!")
await asyncio.sleep(0.7)
@yer.event
async def on_connect():
await yer.change_presence(status=discord.Status.idle,activity=discord.Game("Game"))
@yer.event
async def on_member_join(member):
print("registered")
yer.run(token,bot=False)
【问题讨论】:
标签: python python-3.x discord discord.py chatbot