Python Discord 投票机器人在编码时出错
Python Discord Poll Bot Error Whilst Coding
我不断收到 语法错误,通常是:
require('discord.js');
^ Syntax Error: Invalid Syntax
我正在制作一个 discord bot,其中一个功能是创建一个投票,我的投票代码总是有错误。我认为这与 第 8、14 和 15 行 有关。这也可能与我的 括号 或安装 discord.js 有关。
为什么会这样?这是我的代码的投票部分:
import discord
import os
from dotenv import load_dotenv
load_dotenv()
npm install discord.js
client = discord.Client()
from keep_alive import keep_alive
const {Client, RichEmbed} = require('discord.js');
const bot = new Client();
const token = 'TOKEN'
const PREFIX = 't!'
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
bot.on('message', message =>{
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case "poll":
const Embed = new RichEmbed()
.setColor(0x0096ff)
.setTitle("Poll")
.setDescription("t!poll to make a yes or no poll");
if(largs[1]){
message.channel.send(Embed);
break;
}
let msgArgs = args.slice(1).join(" ");
message.channel.send("**" + msgArgs + "**").then(messageReaction => {
messageReaction.react("");
messageReaction.react("");
message.delete(3000).catch(console.error);
})
break;
}
});
Python 简单轮询代码:
# poll command
@bot.command(description="sets up a poll")
async def poll(ctx, *, arg):
# await ctx.send('{} Poll started by {}: '.format(ctx.message.guild.roles[0], ctx.author.mention))
await ctx.message.delete()
await ctx.send('Poll started by {}: '.format(ctx.author.mention))
m = await ctx.send('`{}`'.format(arg))
await m.add_reaction('')
await m.add_reaction('')
await m.add_reaction('')
我不断收到 语法错误,通常是:
require('discord.js');
^ Syntax Error: Invalid Syntax
我正在制作一个 discord bot,其中一个功能是创建一个投票,我的投票代码总是有错误。我认为这与 第 8、14 和 15 行 有关。这也可能与我的 括号 或安装 discord.js 有关。 为什么会这样?这是我的代码的投票部分:
import discord
import os
from dotenv import load_dotenv
load_dotenv()
npm install discord.js
client = discord.Client()
from keep_alive import keep_alive
const {Client, RichEmbed} = require('discord.js');
const bot = new Client();
const token = 'TOKEN'
const PREFIX = 't!'
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
bot.on('message', message =>{
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case "poll":
const Embed = new RichEmbed()
.setColor(0x0096ff)
.setTitle("Poll")
.setDescription("t!poll to make a yes or no poll");
if(largs[1]){
message.channel.send(Embed);
break;
}
let msgArgs = args.slice(1).join(" ");
message.channel.send("**" + msgArgs + "**").then(messageReaction => {
messageReaction.react("");
messageReaction.react("");
message.delete(3000).catch(console.error);
})
break;
}
});
Python 简单轮询代码:
# poll command
@bot.command(description="sets up a poll")
async def poll(ctx, *, arg):
# await ctx.send('{} Poll started by {}: '.format(ctx.message.guild.roles[0], ctx.author.mention))
await ctx.message.delete()
await ctx.send('Poll started by {}: '.format(ctx.author.mention))
m = await ctx.send('`{}`'.format(arg))
await m.add_reaction('')
await m.add_reaction('')
await m.add_reaction('')