gpt4 book ai didi

python - 如何在 on_member_join() discord.py 中向成员发送私有(private)消息?

转载 作者:行者123 更新时间:2023-12-04 01:32:52 26 4
gpt4 key购买 nike

这就是我所拥有的:

@client.command(pass_context=True)
@client.event
async def on_member_join(ctx, member):
print(f'{member} has joined a server.')
await ctx.send(f"Hello {member}!")
await ctx.member.send(f"Welcome to the server!")

我需要机器人在他加入时发送一条包含规则和命令列表的私有(private)消息。

请帮忙!

最佳答案

我不知道发生了什么,从一天到下一天,机器人停止向新成员发送欢迎消息。但我终于能够解决它。
我只需要添加这两行代码。 intents = discord.Intents() intents.members = True Read

import discord
from discord.ext import commands

#try add this
intents=intents=discord.Intents.all()

#if the above don't work, try with this
#intents = discord.Intents()
#intents.members = True

TOKEN = 'your token'
bot=commands.Bot(command_prefix='!',intents=intents)

#Events
@bot.event
async def on_member_join(member):
await member.send('Private message')

@bot.event
async def on_ready():
print('My bot is ready')

bot.run(TOKEN)

关于python - 如何在 on_member_join() discord.py 中向成员发送私有(private)消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60525993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com