我想做一些简单的聊天命令。我已经在网上进行了一些搜索,但还没有发现任何可以理解的东西
import discord
client = discord.Client()
@client.event
async def on_ready():
print("THE SHEEP BOT IS HERE!")
await client.change_presence(activity=discord.Game("a bot"))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == "Hey":
await client.send_message(message.channel, "Hey.")
client.run("MYTOKEN")
目前,该机器人的状态只是“ A bot”,这很好,我做到了,只是当我作为不和谐类型Hey的用户时,该机器人什么也不做。
我在运行程序时也收到此错误
await client.send_message(message.channel, "Hey.")
AttributeError: 'Client' object has no attribute 'send_message'
答案 0 :(得分:0)
请尝试使用 services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle("Google", options =>
{
options.ClientId = Configuration["Authentication:Google:ClientId"];
options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
options.Events = new OAuthEvents
{
OnCreatingTicket = context =>
{
string domain = context.User.Value<string>("domain");
if (domain != "gmail.com")
throw new GoogleAuthenticationException("You must sign in with a gmail.com email address");
return Task.CompletedTask;
}
};
});
,而不要使用send_message
。
例如:
message.channel.send
顺便说一句,await message.channel.send("Hey.")
不起作用的原因是因为它使用了discord.py的异步版本,该版本已被弃用。 Here's the github issue.