【发布时间】:2020-12-18 01:53:59
【问题描述】:
我目前正在编写一个机器人,我的第一个目标是让机器人受到欢迎并与加入或离开的成员说再见,但机器人什么也没发送,甚至没有显示任何错误。
@client.event
async def on_member_join(member):
print(" System: A member has joined the server!")
def sprint(str):
for c in str + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(3./90)
sprint(" Bot: Oh hey, looks like "+member.name+" has joined..")
#send message to a specific channel
channel = client.get_channel(channel id from the welcome channel)
await channel.send("Hey! Welcome to the server, "+member.mention+"! I hope you read the #rules before doing anything, otherwise have fun and enjoy your stay!")
我上次在重新创建脚本之前就这样做了,但是 on_member_join 的东西不起作用,甚至 on_member_leave 也不起作用! (我首先在做on_member_join 以检查它是否正常工作)
我的备用帐户重新加入了我的服务器,但机器人(MEE6 除外)没有发送任何内容。你们有什么可以帮助我的吗?
【问题讨论】:
-
您是否启用了
intents.members? -
@ŁukaszKwieciński 我在脚本中的任何地方都没有看到
intents.members。我在哪里添加它?这是我的代码的开头:import os import discord import discord.ext from discord.ext import commands TOKEN = 'token from my bot' intents = discord.Intents(members=True) client = discord.Client(intents=intents) bot = commands.Bot(command_prefix='?') @client.event async def on_ready(): print(" System: Bot is ready!")
标签: discord.py