我可以让我的Discord Bot在每周五上午10点向频道的每个成员发送DM吗



我目前正在为我的团队创建一个机器人。我想让Discord Bot在每个周末自动向频道的每个成员发送DM。我一直在使用.j尝试Replit上的代码,还使用了一年前从一个旧线程中找到的代码。

理想情况下,这就是一般流程的样子。

  1. 周五上午10点,Bot会向频道的每个成员发送一个报到提示
  2. 用户响应Bot
  3. Bot说谢谢
  4. Bot将用户的响应发送到指定的管理员

这是我迄今为止的代码,但我遇到了一些语法错误,而且通常都会被卡住。

client.command()
async def dm(ctx, user, discord.User, *, message=None) 
if (message == None)
await ctx.send('You need to put a message')
else
await user.send(message)
await ctx.channel.purge(limit=1)
await ctx.send('DM Successfully Sent')
await ctx.author.send('"' + message + '"' + ' sent to ' + str(user))
print('"' + message + '"' + ' sent to ' + str(user))

有什么想法吗?我感谢所有的见解!

当前您使用discord。PY不是discord.js…

client.command()
async def dm(ctx: commands.Context, user: discord.User, *, message=None):
if message is None:
await ctx.send('You need to put a message')
else:
await user.send(message)
await ctx.message.delete()
await ctx.send('DM Successfully Sent')
await ctx.author.send(f'"{message}" sent to {user.name}')
print(f'"{message}" sent to {user.name}')

这是您发布的代码的正确版本。

你需要什么?向GUILD成员或某些频道的观众发送消息?

UPD:使用命令向具有某些角色的所有成员发送一些消息:!send_DMs @role <message>

client.command(name='send_DMs')
async def send_msg_to_all_memebers_with_role(ctx: commands.Context, role: discord.Role, *, message=None):
await ctx.message.delete()
if message is None:
await ctx.send('You need to put a message after role mention')
else:
for member in ctx.guild.members:
if role in member.roles:
await member.send(message)
await ctx.author.send(f'"{message}" sent to {member.name}')
print(f'"{message}" sent to {member.name}')
await ctx.send('All DMs was successfully sent')

最新更新