如何解决将DM发送给特定的Discord用户
我是菜鸟,正在尝试创建将DM发送给特定用户的漫游器,但它返回并显示以下错误:TypeError: event() missing 1 required positional argument: 'coro'
import discord
import asyncio
import os
from users import user_list
key = open("ID.txt","r").readline()
bot = discord.Client()
@bot.event()
async def DM(ctx,user: user_list,*,message=None):
message = "Come show some love and support to our local streamer by giving him a follow here https://www.twitch.tv/streamer"
await user.send(message)
bot.run(key.strip())
任何帮助将不胜感激。
解决方法
给出代码和其他答案,我觉得有必要在这里使用commands framework
给出完整的示例import discord
from discord.ext import commands
with open("ID.txt",'r') as f:
key = f.readline()
bot = commands.Bot(command_prefix='!')
@bot.command()
async def dm(ctx,user: discord.User,*,message=None):
message = message or "Come show some love and support to our local streamer by giving him a follow here https://www.twitch.tv/streamer"
await user.send(message)
bot.run(key.strip())
可以使用!dm <user> [message]
将其发送给您提及的任何人dm
@commands.Cog.listener()
async def on_message(self,message):
if message.author.bot:
return
if isinstance(message.channel,discord.DMChannel): #CHECKS IF MESSAGE IS IN DM
owner = self.bot.get_user(110877011584503808)
print(
f"{message.author.name}#{message.author.discriminator} <{message.author.id}>: {message.content}"
)
await owner.send(
f"{message.author.name}#{message.author.discriminator} <{message.author.id}>: {message.content}"
) #SENDS THE MESSAGE SENT TO THE BOT,TO THE OWNER
这是我的代码,用于当某人向我的机器人发送dm时。它将在dm中将该人的姓名和消息发送给我
owner = self.bot.get_user(110877011584503808)#定义要将dm发送到的用户。 **使用您要用来分级用户ID的任何方法,将其更改为变量-如果它不是像我的那样定义的用户ID
然后等待所有者。发送将其发送给您将user.id设置为该人的人。
@bot.command()
async def dm(ctx,user: discord.Member):
await user.send("Come show some love and support to our local streamer by giving him a follow here https://www.twitch.tv/streamer")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。